栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

在不停业务的情况下重启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
  }
}
'

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/745121.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号