elasticsearch data节点异常重启导致分配迁移问题

问题

阿里云es服务,某个data node节点状态未知,人工重启节点后,发现变更生效中,一直没有有效变更成功。

1.修改 /_cluster/settings 的 curl 命令

无认证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
curl -X PUT "http://localhost:9200/_cluster/settings" \
-H "Content-Type: application/json" \
-d '{
"persistent": {
"cluster.routing.allocation.enable": null
},
"transient": {
"cluster.routing.allocation.enable": null
}
}'


# 仅清除 transient 设置
curl -X PUT "http://localhost:9200/_cluster/settings" \
-H "Content-Type: application/json" \
-d '{
"transient": {
"cluster.routing.allocation.enable": null
}
}'

认证

1
2
3
4
5
6
7
8
9
10
11
curl -X PUT "http://localhost:9200/_cluster/settings" \
-H "Content-Type: application/json" \
-u elastic:your_password \
-d '{
"persistent": {
"cluster.routing.allocation.enable": null
},
"transient": {
"cluster.routing.allocation.enable": null
}
}'

2.背景解释

  • cluster.routing.allocation.enable 控制分片是否允许分配。
  • 设置为 "none" 表示 不分配任何分片(常用于维护)。
  • 设置为 null(或省略)表示 恢复默认值(默认是 "all",允许分配所有分片)。
  • 使用 PUT 而不是 POST 是官方推荐方式。

3.操作过程

0.curl请求elasticsearch语法
curl -u user:password -X POST <URL> -H "Content-Type: application/json" -d '<JSON 数据>'


1.查看当前es集群集群配置
curl -u elastic:'xxxxx' -XGET  http://xxxx:9200/_cluster/settings

{"persistent":{"cluster":{"routing":{"allocation":{"enable":"none"}}}},"transient":{"cluster":{"routing":{"allocation":{"enable":"none"}}}}}

2.取消维护放开自动分片路由
curl -u elastic:'xxxx'  -X PUT "http://xxxxxx:9200/_cluster/settings" \
  -H "Content-Type: application/json" \
  -d '{
    "transient": {
      "cluster.routing.allocation.enable": null
    }
  }'