【原创】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 ...
随机推荐
- 洛谷——P2820 局域网
P2820 局域网 题目背景 某个局域网内有n(n<=100)台计算机,由于搭建局域网时工作人员的疏忽,现在局域网内的连接形成了回路,我们知道如果局域网形成回路那么数据将不停的在回路内传输,造成 ...
- 洛谷 P1731 [NOI1999]生日蛋糕
P1731 [NOI1999]生日蛋糕 题目背景 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层 生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M ...
- 附加数据库时,提示“Microsoft SQL Server,错误: 5120”, 解决方案
错误的提示内容为:
- How do you check if a variable is an array in JavaScript? [duplicate]
https://stackoverflow.com/questions/767486/how-do-you-check-if-a-variable-is-an-array-in-javascript ...
- Redis 命令行 常用总结
http://www.redis.cn/commands.html# 1 Keys * 列出所有的keys redis > keys * ) "s:0" ) "o: ...
- 一个Exchange 2010 的password不定期弹框的问题处理,希望对大家可以有所帮助。
前期有个客户採用exchange 2010的邮件系统作为他们的邮件平台.有个奇怪的现象就是Exchange 2010 系统会出现不定期"宕机"现象,为何打上引號,就是这个时候仅仅有 ...
- [转] When to use what language and why
Published by Seraphimsan Oct 13, 2010 (last update: Oct 14, 2010) When to use what language and why ...
- 使用 Vagrant 构建开发环境
使用 Vagrant 构建开发环境 摘要:本文描述了如使用 Vagrant 构建统一的开发环境. 问题 作为开发人员,我们通常面临的问题有: 开发环境需要手工安装配置,这包括操作系统(CentOS.U ...
- oracle sql 超长报ORA-01460错误
程序查找数据的时候报错了: ORA-01460: 转换请求无法实施或不合理 这是什么鬼?不合理你就提嘛,报错干什么. 程序原本好好的,现在突然报错了.数据库并没有什么更改. 后来猜测是因为执行的SQL ...
- 2016/05/17 thinkphp3.2.2 ① Ajax 使用 ②前端验证
显示效果: ①Ajax使用: 注意传值的所有过程用的是小写,及时数据库列的名称中有大写字母 控制器部分: AjaxController.class.php <?php namespace H ...