ElasticDump的安装使用

ElasticDump是一个ElasticSearch的数据导入导出开源工具包,方便使用。

官方地址:官方地址:https://github.com/taskrabbit/elasticsearch-dump

 

 

安装方式如下:
安装NodeJS
下载源码:wget http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz
解压:tar xvf node-v0.10.22-linux-x64.tar.gz
配置环境变量:
在/etc/profile文件新增:
export NODE_HOME=/home/node-v0.10.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
执行 source /etc/profile 命令让环境变量设置生效
测试:在终端输入node -v如果有版本信息输出,则说明安装成功

安装NPM
curl -L https://npmjs.org/install.sh | sh

安装ElasticDump
npm install elasticdump -g
elasticdump

使用方式:

执行数据迁移  
导出Mapping信息  
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.29   --output=http://192.168.100.72:9200/xmonitor-prd-2015.04.29  --type=mapping  
  
导出数据  
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.28   --output=/usr/local/esdump/node-v0.12.2-linux-x64/data/xmonitor-prd-2015.04.28.json --type=data  
  
导出数据到本地集群  
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.29   --output=http://192.168.100.72:9200/xmonitor-prd-2015.04.29 --type=data  

要实现ElasticSearch的数据迁移,除了要实现索引中文档对象的迁移外,还需要迁移索引中映射模式的迁移。关于某一个索引的映射信息可以通过ElasticSearch中的_plugin/head插件在web界面通过信息中的索引信息来查阅。如图1所示。

 

配置步骤

elasticdump是实现不同ElasticSearch集群之间索引迁移的工具。默认情况下,ITOA集群部署成功后,该工具存在于安装节点(客户端节点)上。elasticdump语法和常用参数选项如下:

elasticdump --input SOURCE --output DESTINATION [OPTIONS]

其中input/output表示索引数据源和数据目的地

SOURCE/ DESTINATION可以是ElasticSearch集群地址或者文件路径。

SOURCE/ DESTINATIONElasticSearch集群地址时格式如下:

格式: {protocol}://{host}:{port}/{index}

样例: http://127.0.0.1:9200/my_index

SOURCE/ DESTINATION为文件路径时格式如下:

格式: {FilePath}

样例: /Users/evantahler/Desktop/dump.json

OPTIONS常用选项参数有:

--limit

用于限定每一批量操作时进行迁移的文档对象数目,默认值是100,也就是每一次从SOURCE到DESTINATION文档对象数量。

--quiet

只输出错误信息,该参数的默认值是false,如果该参数设置为true。控制台中关于数据迁移的进度信息不可见。

--type

数据迁移类型,可选值有analyzer, data, mapping三种。在ITOA由于统一版本的软件平台analyzer是相同的,所以进行索引迁移时,只需要迁移data, mapping两种类型的数据。该参数的默认选项是data

--ignore-errors

该参数用于控制数据迁移过程遇到错误数据的处理策略。默认情况下为false,表示遇到错误数据时,停止数据迁移。

--help

陈列该工具使用时的帮助信息。

以下两个实例为ElasticSearch和File之间进行索引的data和mapping互相迁移实例。

实例一:将索引(包括datamapping)从ElasticSearch迁移至File

[root@training01 ~]# elasticdump --input=http://172.168.1.139:9200/lion-acg-example --output=/data/my_index_mapping.json --type=mapping

Sat, 17 Jun 2017 07:33:21 GMT | starting dump

Sat, 17 Jun 2017 07:33:21 GMT | got 1 objects from source elasticsearch (offset: 0)

Sat, 17 Jun 2017 07:33:21 GMT | sent 1 objects to destination file, wrote 1

Sat, 17 Jun 2017 07:33:21 GMT | got 0 objects from source elasticsearch (offset: 1)

Sat, 17 Jun 2017 07:33:21 GMT | Total Writes: 1

Sat, 17 Jun 2017 07:33:21 GMT | dump complete

[root@training01 ~]# elasticdump --input=http://172.168.1.139:9200/lion-acg-example --output=/data/my_index_data.json --type=data

Sat, 17 Jun 2017 07:34:33 GMT | starting dump

Sat, 17 Jun 2017 07:34:33 GMT | got 100 objects from source elasticsearch (offset: 0)

Sat, 17 Jun 2017 07:34:33 GMT | sent 100 objects to destination file, wrote 100

Sat, 17 Jun 2017 07:34:33 GMT | got 100 objects from source elasticsearch (offset: 100)

Sat, 17 Jun 2017 07:34:33 GMT | sent 100 objects to destination file, wrote 100

Sat, 17 Jun 2017 07:34:33 GMT | got 100 objects from source elasticsearch (offset: 200)

Sat, 17 Jun 2017 07:34:33 GMT | sent 100 objects to destination file, wrote 100

Sat, 17 Jun 2017 07:34:33 GMT | got 100 objects from source elasticsearch (offset: 300)

……………..

Sat, 17 Jun 2017 07:34:36 GMT | got 0 objects from source elasticsearch (offset: 20561)

Sat, 17 Jun 2017 07:34:36 GMT | Total Writes: 20561

Sat, 17 Jun 2017 07:34:36 GMT | dump complete

实例二:将索引(包括datamapping)从File迁移至ElasticSearch

[root@training01 data]# elasticdump  --input=/data/my_index_data.json --output=http://172.168.1.139:9200/h3c-acg-data --type=data

Sat, 17 Jun 2017 08:37:15 GMT | starting dump

Sat, 17 Jun 2017 08:37:15 GMT | got 100 objects from source file (offset: 0)

Sat, 17 Jun 2017 08:37:16 GMT | sent 100 objects to destination elasticsearch, wrote 100

Sat, 17 Jun 2017 08:37:16 GMT | got 137 objects from source file (offset: 100)

Sat, 17 Jun 2017 08:37:16 GMT | sent 137 objects to destination elasticsearch, wrote 137

Sat, 17 Jun 2017 08:37:16 GMT | got 135 objects from source file (offset: 237)

Sat, 17 Jun 2017 08:37:16 GMT | sent 135 objects to destination elasticsearch, wrote 135

………………..

Sat, 17 Jun 2017 08:37:36 GMT | Total Writes: 20561

Sat, 17 Jun 2017 08:37:36 GMT | dump complete

 [root@training01 data]# elasticdump  --input=/data/my_index_mapping.json     --output=http://172.168.1.139:9200/h3c-acg-data --type=mapping

Sat, 17 Jun 2017 08:37:59 GMT | starting dump

Sat, 17 Jun 2017 08:37:59 GMT | got 1 objects from source file (offset: 0)

Sat, 17 Jun 2017 08:37:59 GMT | sent 1 objects to destination elasticsearch, wrote 10

Sat, 17 Jun 2017 08:37:59 GMT | got 0 objects from source file (offset: 1)

Sat, 17 Jun 2017 08:37:59 GMT | Total Writes: 10

Sat, 17 Jun 2017 08:37:59 GMT | dump complete

 

posted @ 2018-04-13 14:38  道非常道  阅读(1845)  评论(0编辑  收藏  举报