ES平滑下线节点操作手册

检查集群配置

在做节点下线操作之前,建议先检查 master-eligible 节点的数量与 minimum_master_nodes 配置,确认下线节点不会影响集群可用性与稳定性,特别是针对小集群。minimum_master_nodes和具有master资格的node数,一般可以设置为3

discovery.zen.minimum_master_nodes: 3 node.master: true

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

通过以下方式将下线节点从集群路由策略中排除:

# Kibana dev tools PUT _cluster/settings { "transient" : { "cluster.routing.allocation.exclude._ip" : "IP_ADDRESS" } }

上面其实会触发分片的 Allocation 机制,涉及的参数为cluster.routing.allocation.exclude.{attribute},其中 {attribute} 表示节点的匹配方式

_name Match nodes by node name _host_ip Match nodes by host IP address (IP associated with hostname) _publish_ip Match nodes by publish IP address _ip Match either _host_ip or _publish_ip _host Match nodes by hostname _id Match nodes by node id

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

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

执行下列命令,等待集群分片前已完成,集群变绿

# Kibana dev tools GET _cluster/health

停掉节点服务进程

Kill {pid}

恢复集群路由策略

PUT _cluster/settings { "transient": { "cluster.routing.allocation.exclude._ip": null } }

至此节点下线操作完成。这里的目标是将节点从集群中下线剔除,并没有上线操作,如果要再次上线该节点,只需要启动服务即可,节点会自动加入集群并分配分片。


参考资料:

经验分享 程序员 微信小程序 职场和发展