诊断未分配的分片
编辑诊断未分配的分片
编辑分片可能未分配的原因有很多,从配置错误的分配设置到磁盘空间不足。
为了诊断部署中未分配的分片,请按照以下步骤操作
为了诊断未分配的分片,请按照以下步骤操作
使用 Kibana
- 登录到 Elastic Cloud 控制台。
-
在 Elasticsearch 服务 面板上,单击您的部署名称。
如果您的部署名称被禁用,则您的 Kibana 实例可能不健康,在这种情况下,请联系 Elastic 支持。如果您的部署不包含 Kibana,您只需先启用它。
-
打开您部署的侧边导航菜单(位于左上角的 Elastic 徽标下),然后转到 Dev Tools > 控制台。
-
使用 cat shards API 查看未分配的分片。
resp = client.cat.shards( v=True, h="index,shard,prirep,state,node,unassigned.reason", s="state", ) print(resp)
response = client.cat.shards( v: true, h: 'index,shard,prirep,state,node,unassigned.reason', s: 'state' ) puts response
const response = await client.cat.shards({ v: "true", h: "index,shard,prirep,state,node,unassigned.reason", s: "state", }); console.log(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。
resp = client.cluster.allocation_explain( index="my-index-000001", shard=0, primary=True, ) print(resp)
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: true } ) puts response
const response = await client.cluster.allocationExplain({ index: "my-index-000001", shard: 0, primary: true, }); console.log(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。
resp = client.indices.get_settings( index="my-index-000001", flat_settings=True, include_defaults=True, ) print(resp) resp1 = client.cluster.get_settings( flat_settings=True, include_defaults=True, ) print(resp1)
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
const response = await client.indices.getSettings({ index: "my-index-000001", flat_settings: "true", include_defaults: "true", }); console.log(response); const response1 = await client.cluster.getSettings({ flat_settings: "true", include_defaults: "true", }); console.log(response1);
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 查看未分配的分片。
resp = client.cat.shards( v=True, h="index,shard,prirep,state,node,unassigned.reason", s="state", ) print(resp)
response = client.cat.shards( v: true, h: 'index,shard,prirep,state,node,unassigned.reason', s: 'state' ) puts response
const response = await client.cat.shards({ v: "true", h: "index,shard,prirep,state,node,unassigned.reason", s: "state", }); console.log(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。
resp = client.cluster.allocation_explain( index="my-index-000001", shard=0, primary=True, ) print(resp)
response = client.cluster.allocation_explain( body: { index: 'my-index-000001', shard: 0, primary: true } ) puts response
const response = await client.cluster.allocationExplain({ index: "my-index-000001", shard: 0, primary: true, }); console.log(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。
resp = client.indices.get_settings( index="my-index-000001", flat_settings=True, include_defaults=True, ) print(resp) resp1 = client.cluster.get_settings( flat_settings=True, include_defaults=True, ) print(resp1)
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
const response = await client.indices.getSettings({ index: "my-index-000001", flat_settings: "true", include_defaults: "true", }); console.log(response); const response1 = await client.cluster.getSettings({ flat_settings: "true", include_defaults: "true", }); console.log(response1);
GET my-index-000001/_settings?flat_settings=true&include_defaults=true GET _cluster/settings?flat_settings=true&include_defaults=true
- 使用 更新索引设置 和 更新集群设置 API 将设置更改为正确的值,以便允许分配索引。
有关修复未分配分片最常见原因的更多指导,请参阅本指南。
观看此视频,了解监控分配健康状况的演练。