当前位置: 首页 > news >正文

Elasticsearch7.x 集群迁移文档

一、集群样例信息

集群名称:escluster-ali-test

1、源集群:(source_cluster)
节点IP节点名称节点角色是否为master节点
10.200.112.149es2.gj1.china-job.cndata,master
10.200.112.151es1.gj1.china-job.cndata,master
10.200.112.153es3.gj1.china-job.cndata,master
2、目标集群:(target_cluster)
节点IP节点名称节点角色是否为master节点
172.31.2.84es1.gj2.china-job.cndata,master
172.31.0.147es2.gj2.china-job.cndata,master
172.31.0.94es3.gj2.china-job.cndata,master

二、操作步骤

1、集群改造

源集群和目标集群合并成一个大集群,修改目标集群的配置信息。

1.1、目标集群改造
  • 关闭目标集群(配置变更前需保证集群是关闭的)
  • 修改目标集群所有节点的集群名称,与源集群名称一样 cluster.name: target_cluster
  • 修改目标集群所有节点dscovery.zen.ping.unicast.hosts:,把源集群节点IP加入。
    ##指向老节点
    cluster.initial_master_nodes: [“es1.gj1.china-job.cn”,“es2.gj1.china-job.cn”,“es3.gj1.china-job.cn”]
    discovery.zen.ping.unicast.hosts: [“10.200.112.149”, “10.200.112.151”,“10.200.112.153”,“172.31.2.84”, “172.31.0.147”,“172.31.0.94”]

discovery.seed_hosts:

  • 192.168.1.10:9300
  • 192.168.1.11
  • seeds.mydomain.com
    cluster.initial_master_nodes:
  • master-node-a
  • master-node-b
  • master-node-c
1.2、关闭源集群索引均衡功能

防止目标集群节点还未全部加入完成,数据开始迁移。

curl -XPUT "http://10.200.112.149:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{"transient" :{"cluster.routing.rebalance.enable" : "none"}
}'
1.3、启动目标集群加入到源集群

同时保证集群运行的状态为green。

1.4、检查

检查新集群健康状态、节点信息、索引状态

curl -XGET "http://10.200.112.149:9200/_cluster/health?pretty"
curl -XGET "http://10.200.112.149:9200/_cat/nodes?v"
curl -XGET "http://10.200.112.149:9200/_cat/indices?v"

2、数据迁移

1、均衡开启和节点下线

开启均衡和源集群节点数据下线,数据会迁移到目标集群

curl -XPUT "http://172.31.2.84:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.routing.allocation.exclude._ip": "10.200.112.149,10.200.112.151,10.200.112.153","cluster.routing.rebalance.enable" : "all"}
}'或者
curl -XPUT "http://172.31.2.84:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.routing.allocation.exclude._name": "es2.gj1.china-job.cn,es1.gj1.china-job.cn,es3.gj1.china-job.cn","cluster.routing.rebalance.enable" : "all"}
}'
2、检查数据迁移状态,节点迁移结束标准:
curl -X GET '172.31.2.84:9200/_nodes/10.200.112.149/stats/indices/docs?pretty'
curl -X GET '172.31.2.84:9200/_nodes/10.200.112.151/stats/indices/docs?pretty'
curl -X GET '172.31.2.84:9200/_nodes/10.200.112.153/stats/indices/docs?pretty' 

源集群所有节点数据迁移完成,执行结果都为:

"indices" : {"docs" : {"count" : 0,"deleted" : 0}}
3、参数调整

迁移中,可能有IO,网络资源不足情况,可以做一些调整https://www.elastic.co/guide/en/elasticsearch/reference/6.5/shards-allocation.html

  • cluster.routing.allocation.node_concurrent_incoming_recoveries
  • cluster.routing.allocation.node_concurrent_outgoing_recoveries
  • cluster.routing.allocation.node_concurrent_recoveries
  • cluster.routing.allocation.node_initial_primaries_recoveries
curl -XPUT "http://172.31.2.84:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.routing.allocation.cluster_concurrent_rebalance": 6,"cluster.routing.allocation.node_concurrent_recoveries": 10}
}'
4、调整恢复速度

如果索引恢复速度慢,可以对恢复速度进行修改:https://www.elastic.co/guide/en/elasticsearch/reference/6.5/recovery.html

  • indices.recovery.max_bytes_per_sec
curl -XPUT "http://172.31.2.84:9200/_cluster/settings?flat_settings=true&pretty" -H 'Content-Type: application/json' -d'
{"transient": {"indices.recovery.max_bytes_per_sec": "60mb"}
}'

三、更改客户端连接到目标集群节点

将所有连接迁移ES集群的客户端应用ES集群连接配置,由老集群节点调整为新集群节点信息,即:“10.200.112.149”, “10.200.112.151”,“10.200.112.153” 变更为 “172.31.2.84”, “172.31.0.147”,“172.31.0.94”

客户端切换完成后,检查客户端服务与ES集群连接是否正常,对ES的读写是否异常。

四、更改新节点配置文件,并重启(业务需要停止读写)

cluster.initial_master_nodes: [“es1.gj2.china-job.cn”,“es2.gj2.china-job.cn”,“es3.gj2.china-job.cn”,“es3.gj1.china-job.cn”]
discovery.zen.ping.unicast.hosts: [“10.200.112.149”, “10.200.112.151”,“10.200.112.153”,“172.31.2.84”, “172.31.0.147”,“172.31.0.94”]

五、源集群关闭

1、先关闭源集群非master节点

同时检查当前运行集群状态是否为green;如果出现异常,停止操作,恢复当前关闭节点。

操作顺序操作动作
110.200.112.151
210.200.112.153
2、最后关闭源集群master节点

[10.200.112.149, 10.200.112.151,10.200.112.153,172.31.2.84, 172.31.0.147,172.31.0.94]
同时检查当前运行集群状态是否为green。如果出现异常,可以配置discovery.zen.ping.unicast.hosts: [“10.200.112.149”, “10.200.112.151”,“10.200.112.153”,“172.31.2.84”, “172.31.0.147”,“172.31.0.94”],恢复当前关闭节点。

操作顺序操作动作
110.200.112.149
3、检查

关闭所有源集群节点后,检查目标集群是否健康,索引数据是否正常;如果没有问题,分离成功,数据迁移完毕。

六、更改新节点配置文件,并重启

cluster.initial_master_nodes: [“es1.gj2.china-job.cn”,“es2.gj2.china-job.cn”,“es3.gj2.china-job.cn”]
discovery.zen.ping.unicast.hosts: [“172.31.2.84”, “172.31.0.147”,“172.31.0.94”]

七、恢复目标集群配置正常

1、取消节点下线配置
curl -XPUT "http://172.31.2.84:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.routing.allocation.exclude._name": null}
}'curl -XPUT "http://172.31.2.84:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.routing.allocation.cluster_concurrent_rebalance": null,"cluster.routing.allocation.node_concurrent_recoveries": null}
}'

六、可能风险

  1. 在迁移数据时,ES节点物理机出现异常,丢失数据
  2. 网络出现异常,出现脑裂

http://www.mrgr.cn/news/24210.html

相关文章:

  • 浅谈proc目录
  • 带你0到1之QT编程:九、布局Layouts两大手段搞定常用开发
  • 线路及接口基础知识
  • 滚雪球学MyBatis(09):MyBatis与Spring整合
  • sqlserver常用的sql命令
  • 聚观早报 | 2025款比亚迪汉上市;iPhone 16天猫全球同步首发
  • ADCS攻击详解—ESC1
  • 博物馆如何实现3D交互控制展示?
  • JavaSSM框架项目 在线投票系统(ppt+详细文档)
  • memcpy 函数
  • Redis 的数据持久化
  • 水平居中的几种方法(总结)
  • 探索Python中的变量声明、初始化、删除变量与垃圾回收机制
  • python测试开发---vue的常见指令
  • 【C++】面试基础重点知识
  • 模板函数template
  • mysql组合键唯一
  • MySQL连接相关知识点
  • 数据场景练习
  • 新能源汽车BMS 学习笔记篇—AFE 菊花链通信中电容隔离 电感隔离的使用