elk6.2.3集群重启和red状态恢复

1、修改配置文件

修改elasticsearch.yml中path.data属性,添加多路径以逗号分隔

path.data : /opt/data1,/opt/data2

2、查看集群状态

curl -XGET "http://127.0.0.1:9200/_cat/indices"
curl -XGET "http://127.0.0.1:9200/_cat/nodes"
curl -XGET "http://127.0.0.1:9200/_cat/health"

3、关闭索引自动平衡

curl -XPUT -H 'Content-Type: application/json' "http://127.0.0.1:9200/_cluster/settings" -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "none"
}
}'

4、节点重启

5、开启索引自动平衡

curl -XPUT -H 'Content-Type: application/json' "http://127.0.0.1:9200/_cluster/settings" -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}'

6、遇到的问题

有一个索引的某个分片一直处理UNASSIGNED状态,需进行手动分配。

curl -XGET -H 'Content-Type: application/json' 'http://127.0.0.1:9200/_cat/shards' | grep UNASSIGNED #查看未分配的索引分片
curl -XGET -H 'Content-Type: application/json' "http://127.0.0.1:9200/_cat/shards/index?v" #查看索引分片

使用reroute接口进行分配。
reroute 接口支持五种指令:allocate_replica, allocate_stale_primary, allocate_empty_primary,move 和 cancel。
常用的一般是 allocate 和 move,allocate_* 指令。
因为负载过高等原因,有时候个别分片可能长期处于 UNASSIGNED 状态,我们就可以手动分配分片到指定节点上。默认情况下只允许手动分配副本分片(即使用 allocate_replica),所以如果要分配主分片,需要单独加一个 accept_data_loss 选项

7、分配主分片

curl -XPOST -H 'Content-Type: application/json' "http://127.0.0.1:9200/_cluster/reroute" -d '{
"commands" : [ {
"allocate_stale_primary" :
{
"index" : "index", "shard" : 4, "node" : "node56", "accept_data_loss" : true
}
}
]
}'

以上不行的话:方法二

cat recover.sh
#!/bin/bash

master=$(curl -s 'http://localhost:9200/_cat/master?v' | grep -v ' ip ' | awk '{print $1}')
for index in $(curl  -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | awk '{print $1}' | sort | uniq); do
    for shard in $(curl  -s 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | grep $index | awk '{print $2}' | sort | uniq); do
        echo  $index $shard

      curl -XPOST -H 'Content-Type: application/json'  'http://localhost:9200/_cluster/reroute' -d '{
            "commands" : [ {
                  "allocate_empty_primary" : {
                      "index" : "'$index'",
                      "shard" : "'$shard'",
                      "node" : "'$master'",
	              "accept_data_loss" : true
                  }
                }
            ]
        }'

        sleep 1
    done
done

8、分配副分片

curl -XPOST -H 'Content-Type: application/json' "http://127.0.0.1:9200/_cluster/reroute" -d '{
"commands" : [ {
"allocate_replica" :
{
"index" : "index", "shard" : 4, "node" : "node56"
}
}
]
}'

9、kibana进和查询命令

fuser -n tcp 5601

posted @ 2018-07-13 14:45  石Stone头  阅读(1895)  评论(0编辑  收藏  举报