如何重启Elasticsearch集群的节点?
- By : Will
- Category : Elastic Stack
Elastic Stack
1 前言
一个问题,一篇文章,一出故事。
由于笔者需要对Elasticsearch的机器进行硬件升级,因此需要重启Elasticsearch的数据节点。
于是整理此文。
2 最佳实践
2.1 准备工作
2.1.1 查看集群状态
GET /_cat/nodes?v
可加如下显示,
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 10.18.5.8 66 99 0 0.19 0.13 0.15 cdfhilmrstw - azelasticsearch01 10.18.5.12 52 97 0 0.19 0.12 0.14 cdfhilmrstw - azelasticsearch05 10.18.5.10 23 99 0 0.00 0.00 0.00 cdfhilmrstw - azelasticsearch03 10.18.5.11 16 99 0 0.05 0.08 0.08 cdfhilmrstw - azelasticsearch04 10.18.5.9 46 99 0 0.01 0.10 0.15 cdfhilmrstw * azelasticsearch02
注意:“master”列带“*”号的是主节点,主节点应该留到最后重启。
2.2 关闭操作
2.2.1 禁用分片分配
PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "primaries" } }
注意,该操作只允许主分片进行分配,避免在节点重启时不必要的复制操作
2.2.2 停止索引并执行刷新操作
POST /_flush
注意,该操有助于加快分片恢复的过程
2.2.3 暂停机器学习任务和数据馈送(可选)
POST _ml/set_upgrade_mode?enabled=true
注意,机器学习功能需要特定的订阅,没有不用操作
2.2.4 停止节点的服务
systemctl stop elasticsearch
或者关闭服务器做硬件维护,
shutdown -h now
2.3 执行节点变更操作
#执行想做的变更操作,包括系统维护或硬件维护
2.4 恢复操作
2.4.1 启动节点节点
systemctl start elasticsearch
2.4.2 观察节点重新加入集群
GET /_cat/nodes?v
2.4.3 确认集群变为“yellow””状态
GET /_cluster/health
等待状态变为“yellow”,
{ { "cluster_name": "logSystem", "status": "yellow", "timed_out": false, "number_of_nodes": 5, "number_of_data_nodes": 5, "active_primary_shards": 279, "active_shards": 499, "relocating_shards": 0, "initializing_shards": 2, "unassigned_shards": 57, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 89.42652329749103 }
2.4.4 恢复分片
PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": null } }
2.4.5 确认集群变为“gree”状态
GET /_cluster/health
直接显示如下状态,
{ "cluster_name": "logSystem", "status": "green", "timed_out": false, "number_of_nodes": 5, "number_of_data_nodes": 5, "active_primary_shards": 279, "active_shards": 558, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100 }
另外,如下命令可能也能帮助到你,
GET _cat/recovery
2.4.6 恢复机器学习(可选)
POST _ml/set_upgrade_mode?enabled=false
参阅文档
==================
https://www.elastic.co/guide/en/elasticsearch/reference/current/restart-cluster.html
没有评论