Elastic Search 未分配分片

Elastic Search 未分配分片

我的集群状态为绿色,重启服务后,一个分片仍为“未分配”,状态变为黄色。我有 2 台机器,设置了 5 个分片和 1 个副本集。我使用的是默认配置,多播关闭,单播启用。我使用以下方法进行了重新路由

for shard in $(curl -XGET http://localhost:9201/_cat/shards | grep UNASSIGNED | awk '{print $2}'); do
    echo "processing $shard"
    curl -XPOST 'localhost:9201/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "wall", 
                  "shard" : '$shard', 
                  "node" : "node1", 
                  "allow_primary" : false
              }
            }
        ]
    }'
    sleep 5
done

输出如下

{
"acknowledged":true,
"state":{
  "version":48,
  "master_node":"Ar7UpWUQSpSlYcje-u6bgA",
  "blocks":{

  },
  "nodes":{
     "EtQ9mOrLQbiUbHGqeQgMvQ":{
        "name":"node2",
        "transport_address":"inet[/XXX.XXX.XX.XXX:9300]",
        "attributes":{

        }
     },
     "Ar7UpWUQSpSlYcje-u6bgA":{
        "name":"node1",
        "transport_address":"inet[/XXX.XXX.XX.XXX:9301]",
        "attributes":{

        }
     }
  },
  "routing_table":{
     "indices":{
        "wall":{
           "shards":{
              "2":[
                 {
                    "state":"STARTED",
                    "primary":false,
                    "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
                    "relocating_node":null,
                    "shard":2,
                    "index":"wall"
                 },
                 {
                    "state":"STARTED",
                    "primary":true,
                    "node":"Ar7UpWUQSpSlYcje-u6bgA",
                    "relocating_node":null,
                    "shard":2,
                    "index":"wall"
                 }
              ],
              "0":[
                 {
                    "state":"STARTED",
                    "primary":true,
                    "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
                    "relocating_node":null,
                    "shard":0,
                    "index":"wall"
                 },
                 {
                    "state":"INITIALIZING",
                    "primary":false,
                    "node":"Ar7UpWUQSpSlYcje-u6bgA",
                    "relocating_node":null,
                    "shard":0,
                    "index":"wall"
                 }
              ],
              "3":[
                 {
                    "state":"STARTED",
                    "primary":false,
                    "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
                    "relocating_node":null,
                    "shard":3,
                    "index":"wall"
                 },
                 {
                    "state":"STARTED",
                    "primary":true,
                    "node":"Ar7UpWUQSpSlYcje-u6bgA",
                    "relocating_node":null,
                    "shard":3,
                    "index":"wall"
                 }
              ],
              "1":[
                 {
                    "state":"STARTED",
                    "primary":false,
                    "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
                    "relocating_node":null,
                    "shard":1,
                    "index":"wall"
                 },
                 {
                    "state":"STARTED",
                    "primary":true,
                    "node":"Ar7UpWUQSpSlYcje-u6bgA",
                    "relocating_node":null,
                    "shard":1,
                    "index":"wall"
                 }
              ],
              "4":[
                 {
                    "state":"STARTED",
                    "primary":false,
                    "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
                    "relocating_node":null,
                    "shard":4,
                    "index":"wall"
                 },
                 {
                    "state":"STARTED",
                    "primary":true,
                    "node":"Ar7UpWUQSpSlYcje-u6bgA",
                    "relocating_node":null,
                    "shard":4,
                    "index":"wall"
                 }
              ]
           }
        }
     }
  },
  "routing_nodes":{
     "unassigned":[

     ],
     "nodes":{
        "EtQ9mOrLQbiUbHGqeQgMvQ":[
           {
              "state":"STARTED",
              "primary":false,
              "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
              "relocating_node":null,
              "shard":2,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":true,
              "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
              "relocating_node":null,
              "shard":0,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":false,
              "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
              "relocating_node":null,
              "shard":3,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":false,
              "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
              "relocating_node":null,
              "shard":1,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":false,
              "node":"EtQ9mOrLQbiUbHGqeQgMvQ",
              "relocating_node":null,
              "shard":4,
              "index":"wall"
           }
        ],
        "Ar7UpWUQSpSlYcje-u6bgA":[
           {
              "state":"STARTED",
              "primary":true,
              "node":"Ar7UpWUQSpSlYcje-u6bgA",
              "relocating_node":null,
              "shard":2,
              "index":"wall"
           },
           {
              "state":"INITIALIZING",
              "primary":false,
              "node":"Ar7UpWUQSpSlYcje-u6bgA",
              "relocating_node":null,
              "shard":0,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":true,
              "node":"Ar7UpWUQSpSlYcje-u6bgA",
              "relocating_node":null,
              "shard":3,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":true,
              "node":"Ar7UpWUQSpSlYcje-u6bgA",
              "relocating_node":null,
              "shard":1,
              "index":"wall"
           },
           {
              "state":"STARTED",
              "primary":true,
              "node":"Ar7UpWUQSpSlYcje-u6bgA",
              "relocating_node":null,
              "shard":4,
              "index":"wall"
           }
        ]
     }
  },
  "allocations":[]
  }
}

但第 0 个分片仍未分配且状态为黄色。

谢谢

答案1

如果您查看日志,您可能会注意到一个问题,例如磁盘空间不足。

您可以将该索引的副本数减少为 0,然后再减少回 1。

另一件很棒的事情是调整复制速度,因为默认情况下它相当慢。

相关内容