经过测试对比_reindex和logstash在es数据迁移的适用场景,推荐使用_reindex。下一为对比结果:
- _reindex适用场景
Reindex API | Elasticsearch Reference [6.1] | Elastic
- 同一集群不同索引数据迁移
- 不同集群索引数据迁移
- 动态调整迁移速度
- 取消任务
- Built-in,无需安装(反例logstash)
- 5.x - 7.x版本api均包含以上功能(可做为es数据迁移通用方案)
- _reindex、logstash等都通过scroll\bulk API实现读写,性能一样
- logstash等三方工具适合blue-green网络不可达的情况下,作为代理迁移数据 (blue - green不通,blue -> logstash -> green代理)
以下为:XX平台es集群数据迁移模拟测试实施步骤
计划将集群A中的test_201912索引迁移到B集群的索引 test_new_201912
1、创建index模板
xyz平台已存在index模板
curl -XPUT http://<es_ip>:9200/_template/test_template -H 'Content-Type: application/json' -d '{ "order": 0, "index_patterns": [ "test*" ], "settings": { "index": { "number_of_shards": "1", "number_of_replicas": "1", "routing": { "allocation": { "require": { "box_type": "hot" } } } } }, "mappings": {}, "aliases": { "test": {} } }'
2、 创建index
curl -XPUT http:// <es_ip>:9200/test_new_201912
curl http:// <es_ip>:9200/_cat/shards/test_new_201912 # 确认shards在目标主机
3、执行迁移
test_201912
->test_new_201912
curl -XPOST http: //<es_ip>:9200/_reindex?wait_for_completion=false -H 'Content-Type: application/json' -d '{ "source": { "index": "test_201912", "size": 1000 }, "dest": { "index":"test_new_201912 " } }'
记录taskId {"task":"task123456:3208554"}
4、动态调整速度
curl -XPOST http:// <es_ip>:9200/_reindex/task123456:3208554/_rethrottle?requests_per_second=1000
5、取消任务
curl -XPOST http:// <es_ip>:9200/_tasks/task123456:3208554/_cancel
6、删除index
curl -XDELETE http:// <es_ip>:9200/
test_201912
7、.task索引
手动创建_reindex的迁移task后,es会自动创建一个.task的index
- 删除.task,如第 6步操作
- 让es自动迁移.tasks, 如序8
8、逐台下线老节点
版权声明:本文为cqupt2012214390原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。