- 常用查询命令汇总:
集群健康度:
curl http://127.0.0.1:9200/_cat/health?v -u elastic:elastic
节点情况:
curl http://127.0.0.1:9200/_cat/nodes?v -u elastic:elastic
红色索引:
curl http://127.0.0.1:9200/_cat/indices?v -u elastic:elastic | grep -w "red"
磁盘占用情况:
curl http://127.0.0.1:9200/_cat/allocation?v -u elastic:elastic
如果有分片是unassigned,可以执行以下指令:
curl -u elastic:elastic http://127.0.0.1:9200/_cluster/allocation/explain
curl -u elastic:elastic http://127.0.0.1:9200/_cluster/reroute
curl -H "Content-Type: application/json" -XPOST 'http://127.0.0.1:9200/_cluster/reroute' -d '{
"commands" : [ {
"allocate" : {
"index" : "zcqg_goods", #index名称
"shard" : 3, #分片
"node" : "IzLJZiM7TQS0HG9SM4y9QW", # nodeid
"allow_primary" : true
}
}
]
}'
查询所有分片的情况:
curl http://127.0.0.1:9200/_cluster/health?level=shards -u elastic:elastic
curl http://localhost:9200/_cat/shards -u elastic:elastic
- 彻底解决 es 的 unassigned shards 症状
https://toutiao.io/posts/na8zgp/preview
https://www.datadoghq.com/blog/elasticsearch-unassigned-shards/
There are many possible reason why allocation won't occur:
1.You are running different versions of Elasticsearch on different nodes
2.You only have one node in your cluster, but you have number of replicas set to something other than zero.
3.You have insufficient disk space.
4.You have shard allocation disabled.
5.You have a firewall or SELinux enabled. With SELinux enabled but not configured properly, you will see shards stuck in INITIALIZING or RELOCATING forever.
As a general rule, you can troubleshoot things like this:
1.Look at the nodes in your cluster: curl -s 'localhost:9200/_cat/nodes?v'. If you only have one node, you need to set number_of_replicas to 0. (See ES documentation or other answers).
2.Look at the disk space available in your cluster: curl -s 'localhost:9200/_cat/allocation?v'
3.Check cluster settings: curl 'http://localhost:9200/_cluster/settings?pretty' and look for cluster.routing settings
4.Look at which shards are UNASSIGNED curl -s localhost:9200/_cat/shards?v | grep UNASS
5.Try to force a shard to be assigned
curl -XPOST -d '{ "commands" : [ {
"allocate" : {
"index" : ".marvel-2014.05.21",
"shard" : 0,
"node" : "SOME_NODE_HERE",
"allow_primary":true
}
} ] }' http://localhost:9200/_cluster/reroute?pretty
6.Look at the response and see what it says. There will be a bunch of YES's that are ok, and then a NO. If there aren't any NO's, it's likely a firewall/SELinux problem.
基本步骤:
curl -s 'localhost:9200/_cat/allocation?v' -u elastic:elastic
curl 'http://localhost:9200/_cluster/settings?pretty' -u elastic:elastic
curl -s localhost:9200/_cat/shards?v -u elastic:elastic | grep UNASS
curl -XDELETE -u elastic:elastic localhost:9200/索引