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

相關文章
相關標籤/搜索