在不停业务的情况下重启ES集群中的节点

之前写了一篇文章如何安全重启ES集群的节点,这又一个前提,就是需要停止写入业务。但是,有些时候业务是不能停的,又需要重启某一个节点(例如补丁修复,服务器更换等),这就需要用到本篇文章提到的不停业务重启ES节点。

总体思路

将需要重启的节点从集群中删除,然后重新加入,也能起到重启的效果,但是不需要停业务

具体步骤

Step1 开启集群shard自动平衡

一般情况下,集群的自动平衡都是开启的,可以用以下指令查看

$ curl "localhost:9200/_cluster/settings?pretty" 
{
  "persistent" : {
    "cluster" : {
      "routing" : {
        "allocation" : {
          "enable" : "all"
        }
      }
    }
  }
}

如果 “enable” : “all”,则表示自动平衡已经开启,如果没有开启,用以下方法开启自动平衡。

 curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster.routing.allocation.enable": "all"     
  }
}
'

Step2 从ES集群中删除指定节点

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.routing.allocation.exclude._ip" : "10.0.0.1"
  }
}
'

这里可以通过ip,nodename等方法指定需要删除的节点

_name  Match nodes by node name
_host_ip  Match nodes by host IP address (IP associated with hostname)
_publish_ip  Match nodes by publish IP address
_ip  Match either _host_ip or _publish_ip
_host  Match nodes by hostname
_id  Match nodes by node id
_tier  Match nodes by the node’s data tier role

Step3 等待集群自动重新平衡Shard

在同步期间,可以通过以下方法查看集群状态

$ curl 'localhost:9200/_cluster/health?pretty'
{
  "cluster_name" : "natanalyzer",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 6,
  "number_of_data_nodes" : 6,
  "active_primary_shards" : 6694,
  "active_shards" : 6844,
  "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.0
}

当relocating_shards=0的时候,再次确认需要删除的节点上已经没有shard,才执行下一步的操作

curl http://localhost:9200/_cat/shards?v|grep esnode5
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  561k  100  561k    0     0  1029k      0 --:--:-- --:--:-- --:--:-- 1028k

Step4,重新启动节点

Step5,节点重新加入集群

由于重新启动的节点已经被列入集群的exclude列表,需要对其进行清除,以触发shard重新平衡

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.routing.allocation.exclude._name" : null
  }
}
'

综上,就可以在带业务的情况下完成集群节点的重启。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值