Elasticsearch跨集群数据迁移

一、背景

由于新采购了一批性能更好的服务器,再加上公司内领导要求服务器需要统一管理,因ES所在服务器散落在不同位置,所以决定对ES的服务器进行迁移。

二、迁移方案

迁移的思路:

  1. 在新的服务器上搭建ES集群(ES的版本和老集群的相同,均为6.6.1)
  2. 迁移数据
    基于以上思路,找了一些相关迁移工具,并从多个维度进行了比较,如下
tooldata sizeonline/offlinerelated information
elasticsearch-dumpsmallonlinehttps://github.com/taskrabbit/elasticsearch-dump
logstashbigonline
snapshot and restorebigofflinehttps://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
elasticsearch-migrationbigonlinehttps://github.com/medcl/esm-abandoned

经过对比分析,Elasticsearch-Migration不仅适用于在线、迁移数据量大的场景,而且安装和使用都比较简单,最终选择了Elasticsearch-Migration。

四、迁移步骤

1、下载、安装、配置新的ES集群

具体参考:https://blog.csdn.net/wangkai_123456/article/details/87941615

2、在测试环境选择对迁移效率进行测试

3、旧的ES集群停止写入

4、下载安装elasticsearch-migration

源码:https://github.com/medcl/esm-abandoned
编译好的工具:https://github.com/medcl/esm-abandoned/releases

下载编译好的工具放到/usr/local/hadoop目录下,解压后可以直接运行,elasticsearch-migration支持linux,windows等不同系统。使用示例

./bin/linux64/esm -s http://10.62.124.x:9200 -d http://10.67.151.y:9200 -x index_name -w=5 -b=10 -c 10000

-w 表示线程数
-b 表示一次bulk请求数据大小,单位MB默认 5M
-c 一次scroll请求数量

5、数据迁移

因为需要迁移的索引比较多,大概有几百个,为了提高效率,所以写了一个批量索引迁移脚本:

#!/bin/sh

dir="/usr/local/hadoop"
cd $dir

esIndex=`curl -s 'http://10.62.124.x:9200/_cat/indices' | grep -e mobile_lte_* | awk '{print $3}'`

for indexName in $esIndex

do

    echo "Start migration $indexName"
    ./bin/linux64/esm -s http://10.62.124.x:9200 -d http://10.67.151.y:9200 -x $indexName -y $indexName -w=5 -b=10 -c 10000 --copy_settings --copy_mappings --force  --refresh

done

将该脚本放到/usr/local/hadoop目录下,运行即可。

五、迁移过程中的注意点

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值