问题描述:
服务器断电,单机版 es 直接挂掉,再次启动时,发现有 es 状态为red ,有一些 索引副本始终为unssigned,折腾了好长一段时间。
es 我这里状态为 red,只有部分数据可以使用,red 后面 跟着 (xxx of ssss),其中 xxx 是已经恢复的,ssss 是有问题的。
- green
最健康得状态,说明所有的分片包括备份都可用- yellow
基本的分片可用,但是备份不可用(或者是没有备份)- red
部分的分片可用,表明分片有一部分损坏。此时执行查询部分数据仍然可以查到,遇到这种情况,还是赶快解决比较好
没有 es 插件,也可以使用浏览器访问查看es信息:
网页get请求,查看es分片信息:http://localhost:9200/_cluster/health?pretty
网页get请求,查看es健康状态:http://localhost:9200/_cat/health?v
这里的unssigned就是未分配副本分片的问题,接下来执行settings中删除副本分片的命令后, 这个问题就解决了:
[root@elk-node03 ~]# curl -XPUT "http://10.0.8.47:9200/_settings" -H 'Content-Type: application/json' -d' { "number_of_replicas" : 0 } '
返回结果:
{
"acknowledged"
:
true
}
如果还有副本未恢复,这里可以直接删除了。数量不是太多,如果数据比较重要,则需要手动恢复索引了。
手动索引恢复 bash:
#!/usr/bin/env bash
# The script performs force relocation of all unassigned shards,
# of all indices to a specified node (NODE variable)
# 这里你的 ip
ES_HOST="172.16.211.130"
# 这里你的 node
NODE="node-2"
# 注意端口
curl ${ES_HOST}:9210/_cat/shards > shards
grep "UNASSIGNED" shards > unassigned_shards
while read LINE; do
IFS=" " read -r -a ARRAY <<< "$LINE"
INDEX=${ARRAY[0]}
SHARD=${ARRAY[1]}
echo "Relocating:"
echo "Index: ${INDEX}"
echo "Shard: ${SHARD}"
echo "To node: ${NODE}"
curl -s -XPOST "${ES_HOST}:9210/_cluster/reroute" -d "{
\"commands\": [
{
\"allocate\": {
\"index\": \"${INDEX}\",
\"shard\": ${SHARD},
\"node\": \"${NODE}\",
\"allow_primary\": true
}
}
]
}"; echo
echo "------------------------------"
done <unassigned_shards
rm shards
rm unassigned_shards
exit 0
脚本启动命令:bash xxx.sh
启动有问题,可能会出现: