ElasticSearch出现UNASSIGNED SHARDS的解决办法
首先可以查看集群里有多少个未分配的分片, 以及分片是否均匀.
$ curl -XGET "172.18.192.100:9200/_cat/allocation?v" shards disk.indices disk.used disk.avail disk.total disk.percent host ip node 2120 2.8tb 6.2tb 11.6tb 17.9tb 35 172.18.192.101 172.18.192.101 it-elk-node3 3520 5.8tb 5.9tb 12tb 17.9tb 33 172.18.192.102 172.18.192.102 it-elk-node4 764 1tb 2tb 9.3tb 11.3tb 17 172.18.192.100 172.18.192.100 it-elk-node2 1707 UNASSIGNED
一般来说, ES会自动将未分配的shards, 分配到各node上. 使用以下命令确定自动分配分片的功能是打开的
$ curl -XGET http://172.18.192.100:9200/_cluster/settings?pretty
{
"persistent" : {
"cluster" : {
"max_shards_per_node" : "20000" # 一个node可以拥有最大20000个shards
},
"xpack" : {
"monitoring" : {
"collection" : {
"enabled" : "true"
}
}
}
},
"transient" : {
"cluster" : {
"routing" : {
"allocation" : {
"enable" : "all" # 只要cluster.routing.allocation.enable是all的状态, ES就会自动分配shards
}
}
}
}
}
如果自动分配分片功能没有打开, 使用如下命令打开之
# 修改分片数量限制
$ curl -X PUT "172.18.192.100:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{
"persistent" : {
"cluster.max_shards_per_node" : "30000"
}
}'
# 开启自动分片
$ curl -X PUT "172.18.192.100:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}'
然后ES便会自动将shards分配到各node上. 过程可能比较缓慢. 如果想加快分配速度, 可以调高indices.recovery.max_bytes_per_sec 和 cluster.routing.allocation.node_concurrent_recoveries 的值. 这2个配置可以写在ES的配置文件中, 也可以使用如下命令来修改之
$ curl -XPUT "172.18.192.100:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{
"transient" : {
"indices.recovery.max_bytes_per_sec": "500mb"
}
}'
$ curl -XPUT "172.18.192.100:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{
"transient" : {
"cluster.routing.allocation.node_concurrent_recoveries": 10
}
}'
# 查看上面修改过的配置
$ curl -X GET "172.18.192.100:9200/_cluster/settings?pretty"
参考文档:
Elasticsearch常用配置及性能参数
ElasticSearch: Unassigned Shards, how to fix?
Leave a Reply