es版本:6.4
因為一次集群異常,重啟es集群后顯示unassigned shareds。以下是解決辦法
注意:如果網上其他博客的方法執行curl命令總報錯的時候,一定要去官網,選擇自己的版本,查看cluster reroute的文檔。很可能是字段錯了!!!
文檔鏈接給大家留在最后的參考文檔了,可點進去自行選擇版本。
curl elasticsearch_ip:9400/_cat/shards > UNASSIGNED.txt
elasticsearch should?進行篩選用于腳本處理(此命令主要篩選出unassigned狀態的分片的index和shard兩列)
cat UNASSIGNED.txt | grep UNASSIGNED | awk '{print $1,$2}' | uniq > UNASSIGNED-2.txt
由于是6.4版本使用其他博客中的"allocate"都無效。
查閱官網,此版本要使用"allocate_replica"。
但是由于主分片也有問題,所以要使用這個"allocate_stale_primary",將主分片分配給保存過時副本的節點。官網文檔說明了,這個要慎用,可能造成數據丟失。還是先嘗試"allocate_replica"。
cat /root/UNASSIGNED-2.txt | while read line;do
index_name=`echo $line | awk '{print $1}'`
shard_name=`echo $line | awk '{print $2}'`
curl -H 'Content-type: application/json' -XPOST 'http://172.24.27.124:9400/_cluster/reroute' -d '{"commands": [{"allocate_stale_primary": {"index": "'$index_name'","shard": '$shard_name',"node": "g83t-f8sRHS88r_mwVn76Q","accept_data_loss": true}}]
}'
done
index:填寫索引名稱
elasticsearch type。shard:填寫分片id
node:觀察UNASSIGNED.txt文件,看分片不在哪個節點上,就填寫哪個節點。
node值查看方式
curl elasticsearch:9400/_nodes/process?pretty
elasticsearch nested?
Cluster Reroute | Elasticsearch Guide [6.4] | Elastichttps://www.elastic.co/guide/en/elasticsearch/reference/6.4/cluster-reroute.html
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态