文章目录
一、背景
由于新采购了一批性能更好的服务器,再加上公司内领导要求服务器需要统一管理,因ES所在服务器散落在不同位置,所以决定对ES的服务器进行迁移。
二、迁移方案
迁移的思路:
- 在新的服务器上搭建ES集群(ES的版本和老集群的相同,均为6.6.1)
- 迁移数据
基于以上思路,找了一些相关迁移工具,并从多个维度进行了比较,如下
tool | data size | online/offline | related information |
---|---|---|---|
elasticsearch-dump | small | online | https://github.com/taskrabbit/elasticsearch-dump |
logstash | big | online | |
snapshot and restore | big | offline | https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html |
elasticsearch-migration | big | online | https://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目录下,运行即可。