ElasticSearch Troubleshoot
解决 cluster status red
定位 status red 原因
http
# 查看集群健康状态
GET _cat/health?v
# 查看节点分配分片
GET _cat/allocation?v
# 查看分片分片
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
# 查看引起集群健康状态 red 的 unsigned 分片详情
GET _cluster/allocation/explain
{
"index": "my-index-000001",
"shard": 0,
"primary": true
}案例 unsigned shards
案例: 某名为 my-idx 的 index template 中指定了 index.routing.allocation.require.fo: bar ,而 ES 配置为 node.attr.foo: bar , 则 index shard 由于 foo 和 fo 不匹配,无法找到合适的节点分配,会导致 cluster status 从 green 转 red.
修复:
- 修改 index template 中 require.fo: bar 为 require.foo: bar
- 临时去掉已有生成轮转索引、但无法分配的分片的 require.fo 为
null,参考命令:httpPUT .ds-my-idx-000006/_settings { "index.routing.allocation.require.storage": null } - 观察 cluster status 转 green 后,触发轮转生成新索引别名
POST my-idx/_rollover
refs:
- https://www.elastic.co/docs/troubleshoot/elasticsearch/diagnose-unassigned-shards
- https://stackoverflow.com/questions/19967472/elasticsearch-unassigned-shards-how-to-fix
案例 data stream unsigned/unmanaged
同上,查是否有 shard unmanaged 导致。
研测环境可设置零副本
PUT /_settings
{
"index": {
"number_of_replicas": 0
}
}