诊断未分配的分片

编辑

分片未分配的原因有很多,从配置错误的分配设置到磁盘空间不足。

为了诊断部署中未分配的分片,请按照以下步骤操作

为了诊断未分配的分片,请按照以下步骤操作

使用 Kibana

  1. 登录 Elastic Cloud 控制台
  2. Elasticsearch 服务面板上,单击您的部署名称。

    如果您的部署名称被禁用,则您的 Kibana 实例可能不健康,在这种情况下,请联系 Elastic 支持。如果您的部署不包含 Kibana,您只需 先启用它

  3. 打开部署的侧边导航菜单(位于左上角的 Elastic 徽标下方),然后转到开发者工具 > 控制台

    Kibana Console
  4. 使用 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"
      }
    ]

    未分配的分片的stateUNASSIGNEDprirep 值对于主分片为 p,对于副本分片为 r

    示例中的索引有一个主分片未分配。

  5. 要了解为什么未分配的分片未被分配以及必须采取什么措施才能让 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);
    GET _cluster/allocation/explain
    {
      "index": "my-index-000001", 
      "shard": 0, 
      "primary": true 
    }

    我们要诊断的索引。

    未分配的分片 ID。

    指示我们正在诊断主分片。

    响应将如下所示

    {
      "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\"]"  
            }
          ]
        }
      ]
    }

    分片的当前状态。

    分片最初未分配的原因。

    是否分配分片。

    是否将分片分配到特定节点。

    导致节点决策为 no 的决定因素。

    解释为什么决定因素返回 no 决策,并提供一个指向导致该决策的设置的有用提示。

  6. 在本例中,说明表明索引分配配置不正确。要查看您的分配设置,请使用 获取索引设置集群获取设置 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
  7. 使用 更新索引设置集群更新设置 API 将设置更改为正确的数值,以允许分配索引。

有关修复未分配分片最常见原因的更多指导,请按照 本指南 操作,或联系 Elastic 支持