场景介绍
3个节点的es 集群,node1,node2,node3。node3由于故障,重启了节点。重启后node3上的一个副部分片由于某种原因没有恢复上线,集群的健康之是yellow。此时用es 的/_cat/allocation 命令查看发现,node3上的分片个数远少于其他两个节点。
问题分析
node3节点故障下线的时候,原本分布在node3上的分片会逐步迁移到node1,node2上。node3启动后,还没迁移出去的分片会在node3上恢复。由于之前有部分分片已经迁移出去,就导致了node3的分片数量少于其他节点。但是es不是有rebalance机制吗?node3恢复之后,在rebalance机制的均衡下个节点的分片数应该达到均衡才对呀?
其实rebalance的均衡也是要在满足一定的条件后才能触发的,这是由如下配置控制的
cluster.routing.allocation.allow_rebalance
Specify when shard rebalancing is allowed:
always - Always allow rebalancing.
indices_primaries_active - Only when all primaries in the cluster are allocated.
indices_all_active - (default) Only when all shards (primaries and replicas) in the cluster are allocated.
always 表示rebalance一直会开着
indices_primaries_active表示es的主分片都上线才开始rebalance
indices_all_active表示es主分片和副本分片都上线才开始rebalance,这也是es默认的配置
node3上线后有一个分片故障无法上线,不符合indices_all_active的条件,所以es此时没有触发rebalance,节点间的分片也不会均衡。
问题解决
将故障分片所在索引的副本数设置为0,这样es的分片就都上线了,rebalance就会触发。等分片达到均衡后再将索引的副本数设置回来。
如何设置副本数可以参考ES的基本操作
参考文献
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/shards-allocation.html