ElasticSearch6 之failed to fetch index version after copying it over 故障处理

    五节点的elasticsearch6集群中一个节点的硬盘损坏,导致该节点崩溃,在ES_HOME/logs下的log记录中报failed to fetch index version after copying it ove,处理过程颇费周折。ES系统首先进入red状态,说明不是所有的主分片可用,许多主分片显示 unassigned。

curl -XGET http://es-master-node:9200/_cluster/health\?pretty  查看状态

curl -XGET http://es-master-node:9200/_cat/shards     查看集群所有分片状态

curl -s "http://es-master-node:9200/_cat/shards" | grep UNASSIGNED  显示未分配的分片

下面是一个批量处理 UNASSIGNED 的shell脚本,需要注意的是es6中的commands的allocate应当更改为allocate_replica,较老的es版本使用的是allocate

NODE="es-node-ip"  
IFS=$'\n'  
for line in $(curl -s 'http://es-master-ip:9200/_cat/shards' | fgrep UNASSIGNED); do  
  INDEX=$(echo $line | (awk '{print $1}'))  
  SHARD=$(echo $line | (awk '{print $2}'))  
  echo $INDEX
  echo  $SHARD
  curl -XPOST 'http://es-master-ip:9200/_cluster/reroute' -d '{  
     "commands": [  
        {  
            "allocate_replica": {  
                "index": "'$INDEX'",  
                "shard": '$SHARD',  
                "node": "'$NODE'",  
                "allow_primary": true  
          }  
        }  
    ]  
  }'  
done

这个脚本部分系统有报错,下面是另一个成功运行的脚本

NODE="es-node-ip" 
IFS=$'\n'  
for line in $(curl -s 'http://es-master-ip/_cat/shards' | fgrep UNASSIGNED); do  
  INDEX=$(echo $line | (awk '{print $1}'))  
  SHARD=$(echo $line | (awk '{print $2}'))  
  echo $INDEX
  echo  $SHARD
  curl -H 'Content-Type:application/json' -XPOST 'http://es-master-ip:9200/_cluster/reroute?pretty' -d '{  
     "commands": [  
        {  
            "allocate_stale_primary":{
                "index": "'$INDEX'",  
                "shard": '$SHARD',  
                "node": "'$NODE'",  
                "accept_data_loss":true
          }  
        }  
    ]  
  }'  
sleep 5
done
 

但是不是所有的索引都恢复,还需要下面两个操作

curl -XPUT ":9200//_settings?pretty=1" -H 'Content-Type: application/json' -d'
{
    "index" : {
        "number_of_replicas": 0
    }
}'
And then create them again so:

curl -XPUT ":9200//_settings?pretty=1" -H 'Content-Type: application/json' -d'
{
    "index" : {
        "number_of_replicas": 1
    }
}'
下面的shell脚本是进行批量处理的

NODE="es-node-ip" 
IFS=$'\n'  
for line in $(curl -s 'http://es-maste-ip:9200/_cat/shards' | fgrep UNASSIGNED); do  
  INDEX=$(echo $line | (awk '{print $1}'))  
  SHARD=$(echo $line | (awk '{print $2}'))  
  echo $INDEX    $SHARD
curl -XPUT 'http://es-master-ip:9200/"'$index'"/_settings?pretty=1' -H 'Content-Type:application/json' -d '{ "index" :{ "number_of_replicas":0}}'
curl -XPUT 'http://es-master-ip:9200/"'$index'"/_settings?pretty=1' -H 'Content-Type:application/json' -d '{ "index" :{ "number_of_replicas":1}}'
done

 

 

 

 

你可能感兴趣的:(运维)