【原创】Elasticsearch无宕机迁移节点
官方API文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/allocation-filtering.html
参考链接:https://jee-appy.blogspot.com/2016/09/replace-node-elasticsearch-cluster.html
一、测试环境
系统:centos7(虚拟机)
ES版本:5.0.0
节点:三个,node-1(9200)、node-2(9201)、node-3(9202)
说明:以下内容index用“myindex”表示,type用“mytype”表示
二、测试前集群信息
1.查看index配置
http://localhost:9200/myindex/_settings?pretty
{
"myindex": {
"settings": {
"index": {
"creation_date": "1491993018773",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "4GboegTyTQiPoRjbtbLXFA",
"version": {
"created": "5000099"
},
"provided_name": "myindex"
}
}
}
}
2.当前各节点信息
http://localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
0 0b 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-2
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-3
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-1
3.测试三个节点查询
http://localhost:9200/myindex/mytype/_search?pretty
http://localhost:9201/myindex/mytype/_search?pretty
http://localhost:9202/myindex/mytype/_search?pretty
结果:三个节点但会数据总数都为13753,节点正常
4.集群配置信息
http://localhost:9200/_cluster/settings?pretty
{
"persistent": {},
"transient": {}
}
5.索引分片信息
http://localhost:9200/_cat/shards?v
index shard prirep state docs store ip node
三、移除节点
当前有3个节点,node-1、node-2、node-3,由于分片备份数设置为1(上面绿色背景),在node-1和node-3上有全量数据。
现计划将node-1移除,理想的结果是数据转移到node-2和node-3,node-1不再保留数据,然后停止node-1节点。
1.exclude节点
curl -XPUT localhost:9200/_cluster/settings -d '{"transient" :{"cluster.routing.allocation.exclude._name" :"node-1"}}'
参数说明:
①由于es集群数据和配置是共享的,所以在三个节点中任意一个执行上面命令即可,在示例中端口可以是9200、9201、9202。
②exclude的匹配属性支持三种“_name”(节点名)、“_ip”、“_host”,而且值支持通配符匹配,详情见官方API文档。各个节点的三个参数可通过“http://localhost:9200/_cat/allocation?v”查看,对应的列名分别为“node”、“ip”、“host”。因为测试中三个节点的ip和host都相同所以通过"_name"参数区分,需要根据具体情况修改。
③另外,支持exclude和include,值也支持数组如:{"transient" :{"cluster.routing.allocation.exclude._name" :["node-1","node-2"]}}。若上述命令重复执行es配置信息会被覆盖,可以通过“http://localhost:9200/_cluster/settings?pretty”查看当前配置。
2.判断数据迁移结果
http://localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-2
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-3
0 0b 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-1
当shards和disk.indices都为0时表示node-1节点没数据了,数据迁移完成,这时就可以停止node-1节点了。
3.exclude后节点分配情况
http://localhost:9200/_cat/shards?v
index shard prirep state docs store ip node
myindex 0 p STARTED 13753 4.5mb 127.0.0.1 node-3
myindex 0 r STARTED 13753 4.5mb 127.0.0.1 node-2
4.停止node-1节点
http://localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-2
1 4.5mb 5.8gb 11.8gb 17.6gb 33 127.0.0.1 127.0.0.1 node-3
5.重置settings
curl -XPUT localhost:9200/_cluster/settings -d '{"transient" :{"cluster.routing.allocation.exclude._name" :null}}'
三、总结
可以每exclude一个节点完成后,停用这个节点。
也可以一条命令include所有保留的节点并exclude所有不保留的节点,然后停用节点。
【原创】Elasticsearch无宕机迁移节点的更多相关文章
- openstack高可用集群20-openstack计算节点宕机迁移方案
openstack计算节点宕机迁移方案 情景一:/var/lib/nova/instances/ 目录不共享的处理方法(类似手动迁移云主机到其他节点)
- SQL Server 数据库最小宕机迁移方案
一.目的 在做SQL Server数据库维护的时候,当上司要求我们把几十G的数据文件搬动到其它服务器,并且要求最小宕机时间的时候,我们有没什么方案可以做到这些要求呢? 在这里我们假设这两台机器并不是在 ...
- Eureka如何剔除已经宕机的节点
同一个服务部署了多个实例,在通过网关调用时会随机调用其中一个.但是,当某个服务挂掉之后,依然在注册中心中,依然会随机被调用到,调用时便会超时报错.(主要是开发测试或者演示时需要立即将失效的从注册中心剔 ...
- Elasticsearch宕机问题
个人博客:https://blog.sharedata.info/ Elasticsearch 突然宕机,每次重启都只生成错误日志报错信息:## There is insufficient memor ...
- drbd虚拟机宕机恢复方法
问题现象 云南计算节点YN-ec-compute-19因系统盘损坏宕机且操作系统无法恢复,其上本地虚拟机无法疏散且无法迁移 拟采用drbd备份的数据对compute19上的虚拟机进行恢复 恢复方法 1 ...
- Kubernetes 零宕机滚动更新
转载自:https://www.qikqiak.com/post/zero-downtime-rolling-update-k8s/ 软件世界的发展比以往任何时候都快,为了保持竞争力需要尽快推出新的软 ...
- elasticsearch介绍集群,模拟横向扩展节点、节点宕机、改变分片
出处:[http://www.cnblogs.com/dennisit/p/4133131.html] ,防楼主删博,故保留一份! elasticsearch用于构建高可用和可扩展的系统.扩展 ...
- Kubernetes实战指南(三十一):零宕机无缝迁移Spring Cloud至k8s
1. 项目迁移背景 1.1 为什么要在"太岁"上动土? 目前公司的测试环境.UAT环境.生产环境均已经使用k8s进行维护管理,大部分项目均已完成容器化,并且已经在线上平稳运行许久. ...
- Vertica集群单节点宕机恢复方法
Vertica集群单节点宕机恢复方法 第一种方法: 直接通过admintools -> 5 Restart Vertica on Host 第二种方法: 若第一种方法无法恢复,则清空宕机节点的c ...
随机推荐
- SHELL脚本运行的几种方法以及区别
#1 给脚本加上执行权限chmod u+x a.sh, 而后就可以直接用全路径来执行脚本了,比如当前文件夹下用./a.sh,如果如果脚本所在目录在PATH环境变量之中, 则直接用a.sh即可(这和运行 ...
- as3corelib Tutorial:How to Use ArrayUtil Class in Flex
ArrayUtil class contains static utility methods for manipulating and working with Arrays. Note that ...
- hdu 4819 Mosaic
无论是线段树还是树状数组维护最大值最小值的时候一定要注意,如果有修改操作的话,这个最小值和最大值的更新一定不能由原来的和修改的值得到,一定要重新查询一次,否则可能出现当前最小值是原来的未修改值,但事实 ...
- 【SQL Server 学习系列】-- ConnectionTimeout、CommandTimeout和BulkCopyTimeout
1. SqlConnection.ConnectionTimeout获取在尝试建立连接时终止尝试并生成错误之前所等待的时间.单位:秒默认值:15秒设置为0时,表示无限制 2. SqlCommand.C ...
- win7电脑定时开机设置方法
在BIOS设置主界面中选择“Power Management Setup”,进入“电源管理”窗口. 注:缺省情况下,“Resume By Alarm”定时开机选项是关闭的. 将鼠标移到“Resume ...
- 畅通project续
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) ...
- ldd
ldd命令用于判断某个可执行的 binary 档案含有什么动态函式库 [diego@localhost ~/work/branch_dispatch_201511/rtqa_center/source ...
- 鸟哥的Linux私房菜-----12、学习使用Shell scripts
- windows下Python扩展问题error: Unable to find vcvarsall.bat
由于对于Windows下Python扩展不熟,今天遇到一个安装问题,特此做个tag.解决方式在stackoverflow上,网址例如以下: http://stackoverflow.com/quest ...
- oracle sql 超长报ORA-01460错误
程序查找数据的时候报错了: ORA-01460: 转换请求无法实施或不合理 这是什么鬼?不合理你就提嘛,报错干什么. 程序原本好好的,现在突然报错了.数据库并没有什么更改. 后来猜测是因为执行的SQL ...