检查集群配置
在做节点下线操作之前,建议先检查 master-eligible 节点的数量与 minimum_master_nodes 配置,确认下线节点不会影响集群可用性与稳定性,特别是针对小集群。minimum_master_nodes和具有master资格的node数,一般可以设置为3
|
将节点从集群路由策略中排除
通过以下方式将下线节点从集群路由策略中排除:
|
上面其实会触发分片的 Allocation 机制,涉及的参数为cluster.routing.allocation.exclude.{attribute},其中 {attribute} 表示节点的匹配方式
| Match nodes by node name |
| Match nodes by host IP address (IP associated with hostname) |
| Match nodes by publish IP address |
| Match either |
| Match nodes by hostname |
| Match nodes by node id |
执行后将导致该节点上的分片慢慢迁移到其他节点,可能会花几分钟甚至更多的时间,期间不会影响正常业务。
等待所有分区与数据迁移完成
执行下列命令,等待集群分片前已完成,集群变绿
|
停掉节点服务进程
|
恢复集群路由策略
|
至此节点下线操作完成。这里的目标是将节点从集群中下线剔除,并没有上线操作,如果要再次上线该节点,只需要启动服务即可,节点会自动加入集群并分配分片。
参考资料:
https://cloud.tencent.com/developer/article/1596752
https://www.elastic.co/guide/en/elasticsearch/reference/7.6/allocation-filtering.html