官方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无宕机迁移节点的更多相关文章

  1. openstack高可用集群20-openstack计算节点宕机迁移方案

    openstack计算节点宕机迁移方案   情景一:/var/lib/nova/instances/ 目录不共享的处理方法(类似手动迁移云主机到其他节点)

  2. SQL Server 数据库最小宕机迁移方案

    一.目的 在做SQL Server数据库维护的时候,当上司要求我们把几十G的数据文件搬动到其它服务器,并且要求最小宕机时间的时候,我们有没什么方案可以做到这些要求呢? 在这里我们假设这两台机器并不是在 ...

  3. Eureka如何剔除已经宕机的节点

    同一个服务部署了多个实例,在通过网关调用时会随机调用其中一个.但是,当某个服务挂掉之后,依然在注册中心中,依然会随机被调用到,调用时便会超时报错.(主要是开发测试或者演示时需要立即将失效的从注册中心剔 ...

  4. Elasticsearch宕机问题

    个人博客:https://blog.sharedata.info/ Elasticsearch 突然宕机,每次重启都只生成错误日志报错信息:## There is insufficient memor ...

  5. drbd虚拟机宕机恢复方法

    问题现象 云南计算节点YN-ec-compute-19因系统盘损坏宕机且操作系统无法恢复,其上本地虚拟机无法疏散且无法迁移 拟采用drbd备份的数据对compute19上的虚拟机进行恢复 恢复方法 1 ...

  6. Kubernetes 零宕机滚动更新

    转载自:https://www.qikqiak.com/post/zero-downtime-rolling-update-k8s/ 软件世界的发展比以往任何时候都快,为了保持竞争力需要尽快推出新的软 ...

  7. elasticsearch介绍集群,模拟横向扩展节点、节点宕机、改变分片

        出处:[http://www.cnblogs.com/dennisit/p/4133131.html] ,防楼主删博,故保留一份! elasticsearch用于构建高可用和可扩展的系统.扩展 ...

  8. Kubernetes实战指南(三十一):零宕机无缝迁移Spring Cloud至k8s

    1. 项目迁移背景 1.1 为什么要在"太岁"上动土? 目前公司的测试环境.UAT环境.生产环境均已经使用k8s进行维护管理,大部分项目均已完成容器化,并且已经在线上平稳运行许久. ...

  9. Vertica集群单节点宕机恢复方法

    Vertica集群单节点宕机恢复方法 第一种方法: 直接通过admintools -> 5 Restart Vertica on Host 第二种方法: 若第一种方法无法恢复,则清空宕机节点的c ...

随机推荐

  1. PB编译

    java -jar wire-compiler-1.8.0-jar-with-dependencies.jar --java_out=./  ngame.proto 其中java_out是指输出要放在 ...

  2. T1503 愚蠢的宠物 codevs

    http://codevs.cn/problem/1503/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 大家都知道,sh ...

  3. Java面试题总结之Java基础(二)

    Java面试题总结之Java基础(二) 1.写clone()方法时,通常都有一行代码,是什么? 答:super.clone(),他负责产生正确大小的空间,并逐位复制. 2.GC 是什么? 为什么要有G ...

  4. http://www.16aspx.com/Code/Show/5352

    http://www.16aspx.com/Code/Show/5352 可视化工作流引擎RoadFlowV1.3 http://www.cnblogs.com/f2flow/p/4212678.ht ...

  5. Myeclipse配置jad

    下载地址:http://pan.baidu.com/s/1bnpMEuF 1.下载jad158g.win.zip 下载后解压.解压缩后将jad.exe拷贝到自定义的文件夹内:我这里用的是D:/jad/ ...

  6. 关于MSSQL的decimal(numeric)、money、float的使用以及区别

    decimal(numeric).money.float(real) 都是MSSQL中的浮点类型的数据类型. 按存储的范围进行排序 float(real) decimal(numeric) money ...

  7. 【转】Linux下添加新硬盘,分区及挂载

    原文:http://blog.chinaunix.net/uid-25829053-id-3067619.html ------------------------------------------ ...

  8. powerdesign导出SQL时自己主动生成凝视

    1.使用脚本的方式 在里面执行 Option Explicit ValidationMode   = True InteractiveMode   =   im_Batch Dim   mdl   ' ...

  9. Highcharts:X轴分组堆叠图

    在设计一个项目中的数据展示页面时.想要设计双X轴,一个轴显示须要的项.一个轴对这些项进行分组.效果如图: Highcharts自带双X轴展示方式.可是效果不是太理想.调整起来也会麻烦些 看到Highc ...

  10. Linux bash介绍与使用

    Linux————bash的简单使用 对于一个操作系统来说,shell相当于内核kernel外的一层外壳,作为用户接口.一般来说,操作系统的接口分为两类:CLI:command line interf ...