前言

有个集群的ES卡住了,查询后发现是分片恢复太慢导致的。这里记录一下处理方法。


一、查看集群当前状态

 curl -X GET "localhost:9200/_cluster/allocation/explain?pretty"
# 核心提示
{
  "note" : "No shard was specified in the explain API request, so this response explains a randomly chosen unassigned shard. There may be other unassigned shards in this cluster which cannot be assigned for different reasons. It may not be possible to assign this shard until one of the other shards is assigned correctly. To explain the allocation of other shards (whether assigned or unassigned) you must specify the target shard in the request to this API.",
  "index" : "node.k8s.kube-apiserver-2025.11.26",
  "shard" : 0,
  "primary" : true,
  "current_state" : "unassigned",
  "unassigned_info" : {
    "reason" : "CLUSTER_RECOVERED",
    "at" : "2026-04-09T06:30:40.318Z",
    "last_allocation_status" : "throttled"
  },
  "can_allocate" : "yes",
  "allocate_explanation" : "Elasticsearch can allocate the shard.",

集群属于拥堵状态,分片在排队。

二、解决步骤

解决限流,加速恢复

curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster.routing.allocation.node_concurrent_incoming_recoveries": 4,
    "cluster.routing.allocation.node_concurrent_outgoing_recoveries": 4,
    "cluster.routing.allocation.node_concurrent_recoveries": 4,
    "cluster.routing.allocation.cluster_concurrent_rebalance": 4
  }
}'

触发重试

curl -X POST "localhost:9200/_cluster/reroute?retry_failed=true"

观察恢复状态

[root@a es]# curl -s "localhost:9200/_cluster/health?pretty" | grep unassigned_shards
  "unassigned_shards" : 1553,
  "delayed_unassigned_shards" : 0,
[root@a2 es]# curl -s "localhost:9200/_cluster/health?pretty" | grep unassigned_shards
  "unassigned_shards" : 1215,
  "delayed_unassigned_shards" : 0,
[root@a es]# curl -s "localhost:9200/_cluster/health?pretty" | grep unassigned_shards
  "unassigned_shards" : 1179,
  "delayed_unassigned_shards" : 0,
[root@a es]# curl -s "localhost:9200/_cluster/health?pretty" | grep unassigned_shards
  "unassigned_shards" : 822,
  "delayed_unassigned_shards" : 0,
[root@a es]# curl -s "localhost:9200/_cluster/health?pretty" | grep unassigned_shards
  "unassigned_shards" : 335,
  "delayed_unassigned_shards" : 0,

数量逐渐减少,说明好使

总结

记录一下ES提高分片恢复速度的处理方法

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐