【原创】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 ...
随机推荐
- js82:CSS的Style,image的重定位,getElementById,getElementsByTagName,location.href
原文发布时间为:2008-11-10 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
- PHP获得真实客户端的真实IP REMOTE_ADDR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FOR[]转载
REMOTE_ADDR 是你的客户端跟你的服务器“握手”时候的IP.如果使用了“匿名代理”,REMOTE_ADDR将显示代理服务器的IP. HTTP_CLIENT_IP 是代理服务器发送的HTTP头. ...
- 并发编程——IO模型
前言 同步(synchronous):一个进程在执行某个任务时,另外一个进程必须等待其执行完毕,才能继续执行 #所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不会返回.按照这个定义, ...
- 修改textfield的占位符颜色
[self.titleField setValue:UIColorFromHEXWithAlpha(0x999999, 1) forKeyPath:@"_placeholderLabel.t ...
- Spring中使用存储过程
以下内容引用自http://wiki.jikexueyuan.com/project/spring/jdbc-framework-overview/sql-stored-procedure-in-sp ...
- 微服务 Framework
Dubbo :https://github.com/dubbo Spring Cloud :https://github.com/spring-cloud
- javascript实现 京东淘宝等商城的商品图片大图预览功能(图片放大器)
在京东和淘宝等购买东西的时候,我们会经常预览左侧商品展示图片,把鼠标放到原图,右侧就会有个大图显示出细节.本文将带领大家写一个这样简单的功能! 一.实现原理 当鼠标移入某一图片内部时,图片上部会出 ...
- Linux源代码分析工具-Source Insight
下载地址:http://www.sourceinsight.com/down35.html 可用注冊码:SI3US-205035-36448 使用说明:http://wenku.baidu.com/v ...
- Meteor计时器
Meteor有提供它自己的setTimeout和setInterval方法.这些方法被用于确保所有全局变量都具有正确的值.它们就像普通 JavaScript 中的setTimeout 和 setInt ...
- IEnumerator<TItem>和IEnumerator Java 抽象类和普通类、接口的区别——看完你就顿悟了
IEnumerable 其原型至少可以说有15年历史,或者更长,它是通过 IEnumerator 来定义的,而后者中使用装箱的 object 方式来定义,也就是弱类型的.弱类型不但会有性能问题,最主要 ...