Elasticsearch多种方案数据迁移

Elasticsearch数据迁移

注意:Elasticsearch同版本数据迁移,只需将数据存储目录的文件拷贝到新集群path,重启es集群,即可自动recovery,迁移效率最快。这种方案需要重新给启动用户赋权限,然后es启动即可。

不同版本可采取以下方案:

方案1:使用Elasticsearch-Exporter迁移
1.Elasticsearch-Exporter简介:
将ES中的数据向其他导出的简单脚本实现。
2.Elasticsearch-Exporter安装:

npm install nomnom
npm install colors
npm install elasticsearch-exporter --production

在这里插入图片描述
3.Elasticsearch-Exporter使用:
node exporter.js -a <source hostname> -b <target hostname> -p <s port> -q <t port> -i <s index> -j <t index> 即可实现跨机器索引的迁移
在这里插入图片描述
4.Elasticsearch-Exporter索引迁移:
在这里插入图片描述
上图代表同步成功。
源es版本1.6.0,目标es版本2.3.4,
验证发现:可以使用Elasticsearch-Exporter跨机器、跨ES版本同步索引成功。

方案2:使用elasticsearch-dump迁移
1.elasticsearch-dump简介
移动和保存索引的工具。
elasticdump是实现不同ElasticSearch集群之间索引迁移的工具。默认情况下,ITOA集群部署成功后,该工具存在于安装节点(客户端节点)上。
这种方式需要注意的是dump过去的es索引对应的分片和副本都是1
2.elasticsearch-dump安装

yum install epel-release
yum install nodejs
yum install npm
npm install elasticdump
cd node_modules/elasticdump/bin

后便可以执行操作。
在这里插入图片描述
3.elasticsearch-dump使用
#拷贝analyzer如分词

elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=analyzer

#拷贝映射

elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping

#拷贝数据

elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=data

在这里插入图片描述
4.elasticsearch-dump实战总结

elasticdump --input SOURCE --output DESTINATION [OPTIONS]
其中input/output表示索引数据源和数据目的地
SOURCE/ DESTINATION可以是ElasticSearch集群地址或者文件路径。
当SOURCE/ DESTINATION为ElasticSearch集群地址时格式如下:
格式: {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
陈列该工具使用时的帮助信息。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

方案3:使用logstash定向索引迁移

1.下载logstash
2.使用方法

[root@N3 bin]# cat ./logstash_output_mongo/logstash_es22es.conf
input {
  elasticsearch {
  hosts => [ "100.200.10.54:9200" ]
  index => "doc"
  size => 1000
  scroll => "5m"
  docinfo => true
  scan => true
  }
}

filter {
json {
  source => "message"
  remove_field => ["message"]
  }
  mutate {
  # rename field from 'name' to 'browser_name'
  rename => { "_id" => "wid" }
}
}

output {
  elasticsearch {
  hosts => [ "100.20.32.45:9200" ]
  document_type => "docxinfo"
  index => "docx"
  }

  stdout {
  codec => "dots"
  }

}

在这里插入图片描述
方案4:使用reindex迁移

1.reindex说明
reindex实现跨集群的数据迁移时,需要在源es配置文件中添加目标集群为白名单。
2.使用方法

curl -XPOST 'localhost:9200/_reindex?pretty' -d' { "source": { "index": "test2" }, "dest": { "index": "test3" } } '

size是批量提交参数,多少条数据提交一次。调整此参数,最大化reindex效率。
在这里插入图片描述

  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值