當集羣中個別節點出現故障預警等狀況,須要進行退役工做,即讓全部位於該退役節點上的分片的數據分配到其餘節點上後,再將此節點關閉並從集羣中移除。
一、ES提供了讓某個節點上全部數據都移走的功能以下:
ElasticSearch集羣就會自動把這個節點上的全部分片,都自動轉移到其餘節點上,等到轉移完成,這個空節點就能夠毫無影響的下線。html
curl -XPUT 127.0.0.1:9200/_cluster/settings -d '{ "transient" :{ "cluster.routing.allocation.exclude._ip" : "10.0.0.1" } }'
二、當shard都遷移走後,就能夠將此機器上的ES進程關閉
三、能夠在管理頁面上刪除此節點的ES服務角色node
退役ElasticSearch server 節點時,在頁面上進行刪除該節點後,replia不爲0的index恢復過來,可是致使副本爲0的index未能進行shard的分配,致使集羣始終是red狀態。
方式一:跟客戶確認該未成功分配分片的索引有沒有用,沒用就直接刪除便可。
方式二:
一、查看ES集羣的健康情況curl -XGET http://localhost:9200/_cluster/health\?pretty
二、查找未分配的分配curl -s "http://localhost:9200/_cat/shards" | grep UNASSIGNED
json
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ { "allocate" : { "index" : "rs_wx_test",#unsigned 的索引 "shard" : 1,#出現unsigned的切片編號 "node" : "AfUyuXmGTESHXpwi4OExxx",#目標節點 "allow_primary" : true } } ] }'
方式三:增長節點數或者減小副本數:
這裏選擇減小副本數爲爲例:app
curl -H "Content-Type: application/json" -XPUT 'localhost:9200/employee/_settings?pretty' -d '{ "number_of_replicas": 1 #之前副本數爲2的時候出現了shards unsigned,現將副本數設置爲1,恢復正常 }'