Elasticsearch7.8集群实践记录之下线节点

发布时间 2023-09-06 11:58:39作者: 金仙儿追鹿仙

1.背景:由于机房迁移需要将elasticsearch集群进行跨机房搬迁,采取先扩容再收缩的方式进行,已有效减小对业务环境的影响。当前需要将老的节点有序下线。

2.操作步骤:

   1.检查集群配置,保证主节点的可用性;

     

# 设置 minimum_master_nodes 为 2
curl -XPUT 'http://hostname:9200/_cluster/settings' -H 'Content-Type: application/json' -d '{
  "persistent" : {
    "discovery.zen.minimum_master_nodes" : 2
  }
}'

   2. 将节点从集群路由策略中排除

curl -XPUT http://hostname:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d '{
  "transient": {
    "cluster.routing.allocation.exclude._name": "{node.name}"
  }
}'

注意:执行后将导致 {node.name} 节点上的分片慢慢迁移到其他节点,可能会花几分钟甚至更多的时间,期间不会影响正常业务。

  3. 等待所有分区与数据迁移完成

      1.同时可以检查集群的运行状态: _cluster/health?pretty

      2.查看节点数据是否迁移完毕:_node/{node.name}/stats/indices?pretty

4.停掉节点服务进程

5.恢复集群路由策略

curl -XPUT http://hostname:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d '{
  "transient": {
    "cluster.routing.allocation.exclude._name": null
  }
}'