DBAtlas · 数据库运维图谱

Elasticsearch 集群 red/yellow 与未分配分片

症状

_cluster/health 为 'red' 或 'yellow';存在未分配分片;读/写受限或数据无法访问。

1. 颜色与原因

yellow = 副本分片未分配(数据存在,但冗余降低)。red = 至少有一个主分片缺失(该部分数据无法访问)。首先确定是哪一种以及原因。

Elasticsearch

GET _cluster/health?level=indices
GET _cluster/allocation/explain

2. 列出未分配分片及原因

unassigned.reason 列给出根本原因(NODE_LEFT、ALLOCATION_FAILED、DISK 等)。

Elasticsearch

GET _cat/shards?v&h=index,shard,prirep,state,unassigned.reason&s=state

3. 处理常见原因

1) 磁盘水位线 → 超过 low 时,节点不再接收新分片;达到 flood_stage 时,索引变为只读。2) 节点宕机 / 离开。3) 分配被保持在禁用状态。4) 副本数 > 符合条件的节点数。

4. 修复

根据实际原因解除阻塞。

Elasticsearch

# If disk space was freed, remove the read-only block (7.4+ also lifts it automatically once below the high watermark):
PUT _all/_settings {"index.blocks.read_only_allow_delete": null}
# If allocation was left restricted, return it to the default (all):
PUT _cluster/settings {"persistent":{"cluster.routing.allocation.enable":null}}
# Retry failed allocations:
POST _cluster/reroute?retry_failed=true

5. 若仍为 red 且主分片确实已丢失

从快照还原受影响的索引,或从源数据重新索引(_reindex)。永久措施:磁盘水位线告警、合适的副本数(≥1)以及节点健康监控。

在 DBAtlas 中打开 →