One - One Code All

Blog Content

ElasticSearch-安全重启集群节点,升级节点

ElasticSearch   2018-07-07 00:22:43

ES 集群,有时候可能需要修改配置,增加硬盘,扩展内存等操作,需要对节点进行维护升级。但是业务不能停,如果直接kill 掉节点,可能导致数据丢失。而且集群会认为该节点挂掉了,就开始转移数据,当重启之后,它又会恢复数据,如果你当前的数据量已经很大了,这是很耗费机器和网络资源的。


本文转载官方提供的安全重启集群节点的方法:


第一步:先暂停集群的shard 自动均衡。

curl -XPUT http://localhost:9200/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}'


第二步:shutdown你要升级的节点

curl -XPOST http://localhost:9200/_cluster/nodes/_local/_shutdown

Elasticsearch 2.3 版本中shutdown api 已经删除了,我们可以使用kill 方式shutdown。


第三步:升级重启该节点,并确认该节点重新加入到了集群中。

su - elasticsearch -s /bin/bash -c "/usr/local/elasticsearch/elasticsearch-5.4.0/bin/elasticsearch -d -p /tmp/elasticsearch.pid"
 
curl localhost:9200/_cat/nodes


第四步:重复2-3 步,升级重启其它要升级的节点。


第五步:重新启动集群的shard 均衡

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d'
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'


第六步:检查集群的健康度

curl http://127.0.0.1:9200/_cat/health?v
curl localhost:9200/_cluster/health?pretty

当status 转为green 时,集群健康度才正常。

到此整个集群安全升级并且重启结束。



上一篇:通过nodejs的elasticdump工具进行elasticsearch索引和mapping导入导出命令
下一篇:使用node的elasticdump做数据迁移

The minute you think of giving up, think of the reason why you held on so long.