滚动重启/滚动升级(逐个节点,避免不必要的分片移动)
Elasticsearch集群/节点命令
# 1) Disable replica allocation (only primaries are allocated):
PUT _cluster/settings
{
"persistent": { "cluster.routing.allocation.enable": "primaries" }
}
# 2) Optional: stop indexing and flush to speed up recovery:
POST _flush
# 3) Stop one node, do the maintenance, start it; verify it joined:
GET _cat/nodes?v&h=name,version,node.role,master,heap.percent
# 4) Re-enable allocation:
PUT _cluster/settings
{
"persistent": { "cluster.routing.allocation.enable": null }
}
# 5) Wait for green before moving to the next node:
GET _cluster/health?wait_for_status=green&timeout=10m作用
给出逐个重启或升级节点的顺序,同时在节点停机时防止副本被重新复制到其他节点;节点回归后,分片可从本地副本快速恢复。
适用场景
因操作系统补丁、JVM/heap 变更、elasticsearch.yml 变更或小/大版本升级而依次重启节点时。
注意
不等到 green 就不要处理下一个节点;同时有两个节点停机时,某个分片的所有副本可能都不存在了。具备主节点资格的节点最后重启,且每次一个;若失去多数派,集群将无法选出主节点。若忘记重新启用 allocation.enable,副本会一直未分配。升级时先升级数据节点(先 frozen/cold,最后 hot),再升级主节点。