ElasticSearch重启以后shard未分配问题的解决

环境:docker

  • Ubuntu16.04
  • elasticsearch 6.2.3
  • 3个master节点,10个data节点
  • 每一个分片有一个副本

故障:负载均衡

    将一个数据节点的elasticsearch换成docker elasticsearch,分词器没有添加到plugins中。随后把分词器添加到plugins中后,发现有的分片没有被分配,可是ES集群启动正常,只不过一直是yellow状态。并且unassigned分片一直未被分配elasticsearch

解决办法

首先执行:GET user/_recovery?active_only=true 发现集群并无进行副本恢复。spa

点击未进行分配的分片,发现allocation_status: "no_attempt"code

缘由是:shard 自动分配 已经达到最大重试次数5次,仍然失败了,因此致使"shard的分配状态已是:no_attempt"。这时在Kibana Dev Tools,执行命令:POST /_cluster/reroute?retry_failed=true便可。由index.allocation.max_retries参数来控制最大重试次数。orm

The cluster will attempt to allocate a shard a maximum of index.allocation.max_retries times in a row (defaults to 5), before giving up and leaving the shard unallocated.索引

当执行reroute命令对分片从新路由后,ElasticSearch会自动进行负载均衡,负载均衡参数cluster.routing.rebalance.enable默认为true。 ci

It is important to note that after processing any reroute commands Elasticsearch will perform rebalancing as normal (respecting the values of settings such as cluster.routing.rebalance.enable) in order to remain in a balanced state.路由

 总结

通常来讲,ElasticSearch会自动分配 那些 unassigned shards,当发现某些shards长期未分配时,首先看下是不是由于:为索引指定了过多的primary shard 和 replica 数量,而后集群中机器数量又不够。另外一个缘由就是本文中提到的:因为故障,shard自动分配达到了最大重试次数了,这时执行 reroute 就能够了。rem

相关文章
相关标签/搜索