诊断未分配分片
编辑诊断未分配分片编辑
分片未分配的原因有很多,从配置错误的分配设置到磁盘空间不足都有。
为了诊断部署中的未分配分片,请使用以下步骤
为了诊断未分配分片,请遵循以下步骤
使用 Kibana
- 登录 Elastic Cloud 控制台。
-
在 Elasticsearch 服务 面板中,单击您的部署名称。
如果您的部署名称被禁用,您的 Kibana 实例可能不健康,在这种情况下,请联系 Elastic 支持。如果您的部署不包含 Kibana,您只需要 先启用它。
-
打开您的部署的侧边导航菜单(位于左上角的 Elastic 徽标下方),然后转到 开发工具 > 控制台。
-
使用 cat shards API 查看未分配的分片。
response = client.cat.shards( v: true, h: 'index,shard,prirep,state,node,unassigned.reason', s: 'state' ) puts response
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
响应将如下所示
[ { "index": "my-index-000001", "shard": "0", "prirep": "p", "state": "UNASSIGNED", "node": null, "unassigned.reason": "INDEX_CREATED" } ]
未分配的分片具有
state
为UNASSIGNED
。prirep
值对于主分片为p
,对于副本为r
。示例中的索引有一个主分片未分配。
-
要了解为什么未分配的分片没有被分配以及您必须采取什么措施才能让 Elasticsearch 分配它,请使用 集群分配解释 API。
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: true } ) puts response
响应将如下所示
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "unassigned", "unassigned_info" : { "reason" : "INDEX_CREATED", "at" : "2022-01-04T18:08:16.600Z", "last_allocation_status" : "no" }, "can_allocate" : "no", "allocate_explanation" : "Elasticsearch isn't allowed to allocate this shard to any of the nodes in the cluster. Choose a node to which you expect this shard to be allocated, find this node in the node-by-node explanation, and address the reasons which prevent Elasticsearch from allocating this shard there.", "node_allocation_decisions" : [ { "node_id" : "8qt2rY-pT6KNZB3-hGfLnw", "node_name" : "node-0", "transport_address" : "127.0.0.1:9401", "roles": ["data_content", "data_hot"], "node_attributes" : {}, "node_decision" : "no", "weight_ranking" : 1, "deciders" : [ { "decider" : "filter", "decision" : "NO", "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]" } ] } ] }
-
我们案例中的解释表明索引分配配置不正确。要查看您的分配设置,请使用 获取索引设置 和 集群获取设置 API。
response = client.indices.get_settings( index: 'my-index-000001', flat_settings: true, include_defaults: true ) puts response response = client.cluster.get_settings( flat_settings: true, include_defaults: true ) puts response
GET my-index-000001/_settings?flat_settings=true&include_defaults=true GET _cluster/settings?flat_settings=true&include_defaults=true
- 使用 更新索引设置 和 集群更新设置 API 将设置更改为正确的值,以允许分配索引。
有关修复未分配分片最常见原因的更多指导,请遵循 本指南 或联系 Elastic 支持。
为了诊断未分配的分片,请遵循以下步骤
-
使用 cat shards API 查看未分配的分片。
response = client.cat.shards( v: true, h: 'index,shard,prirep,state,node,unassigned.reason', s: 'state' ) puts response
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
响应将如下所示
[ { "index": "my-index-000001", "shard": "0", "prirep": "p", "state": "UNASSIGNED", "node": null, "unassigned.reason": "INDEX_CREATED" } ]
未分配的分片具有
state
为UNASSIGNED
。prirep
值对于主分片为p
,对于副本为r
。示例中的索引有一个主分片未分配。
-
要了解为什么未分配的分片没有被分配以及您必须采取什么措施才能让 Elasticsearch 分配它,请使用 集群分配解释 API。
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: true } ) puts response
响应将如下所示
{ "index" : "my-index-000001", "shard" : 0, "primary" : true, "current_state" : "unassigned", "unassigned_info" : { "reason" : "INDEX_CREATED", "at" : "2022-01-04T18:08:16.600Z", "last_allocation_status" : "no" }, "can_allocate" : "no", "allocate_explanation" : "Elasticsearch isn't allowed to allocate this shard to any of the nodes in the cluster. Choose a node to which you expect this shard to be allocated, find this node in the node-by-node explanation, and address the reasons which prevent Elasticsearch from allocating this shard there.", "node_allocation_decisions" : [ { "node_id" : "8qt2rY-pT6KNZB3-hGfLnw", "node_name" : "node-0", "transport_address" : "127.0.0.1:9401", "roles": ["data_content", "data_hot"] "node_attributes" : {}, "node_decision" : "no", "weight_ranking" : 1, "deciders" : [ { "decider" : "filter", "decision" : "NO", "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]" } ] } ] }
-
我们案例中的解释表明索引分配配置不正确。要查看您的分配设置,请使用 获取索引设置 和 集群获取设置 API。
response = client.indices.get_settings( index: 'my-index-000001', flat_settings: true, include_defaults: true ) puts response response = client.cluster.get_settings( flat_settings: true, include_defaults: true ) puts response
GET my-index-000001/_settings?flat_settings=true&include_defaults=true GET _cluster/settings?flat_settings=true&include_defaults=true
- 使用 更新索引设置 和 集群更新设置 API 将设置更改为正确的值,以允许分配索引。
有关修复未分配分片最常见原因的更多指导,请遵循 本指南。