elasticsearch should,ElasticSearch-解決unassigned shareds問題

 2023-11-11 阅读 20 评论 0

摘要:背景 es版本:6.4 因為一次集群異常,重啟es集群后顯示unassigned shareds。以下是解決辦法 注意:如果網上其他博客的方法執行curl命令總報錯的時候,一定要去官網,選擇自己的版本,查看cluster reroute的文檔。很可能是字段錯了࿰

背景

es版本:6.4

因為一次集群異常,重啟es集群后顯示unassigned shareds。以下是解決辦法

注意:如果網上其他博客的方法執行curl命令總報錯的時候,一定要去官網,選擇自己的版本,查看cluster reroute的文檔。很可能是字段錯了!!!

文檔鏈接給大家留在最后的參考文檔了,可點進去自行選擇版本。

1.獲取unassigned shareds信息

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

2.使用腳本重新分配主分片路由

由于是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

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/173457.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息