Elasticsearch索引迁移的四种方式

Elasticsearch索引迁移的四种方式本文主要讲解Elasticsearch下实现索引迁移的几种方式。0、引言将ES中的索引拷贝到其他ES中,或者将ES整体迁移,研究发现有两个开源的工具:elaticserch-dump和Elasticsearch-Exporter。除此之外,logstash在索引同步、迁移方面的作用也很大。两工具及logstash实现迁移的介绍、安装、使用、验证效果等展示如下:1、el…

大家好,又见面了,我是你们的朋友全栈君。

Elasticsearch 最少必要知识实战教程直播回放

本文主要讲解Elasticsearch下实现索引迁移的几种方式。
#0、引言
将ES中的索引拷贝到其他ES中,或者将ES整体迁移,研究发现有两个开源的工具:elaticserch-dump和 Elasticsearch-Exporter。
除此之外,logstash在索引同步、迁移方面的作用也很大。
两工具及logstash实现迁移的介绍、安装、使用、验证效果等展示如下:

#1、elasticsearch-dump迁移
##1.1 elasticsearch-dump简介
Tools for moving and saving indicies. 从来移动和保存索引的工具。
https://github.com/taskrabbit/elasticsearch-dump

##1.2 elasticsearch-dump安装

1) yum install epel-release
2) yum install nodejs
3) yum install npm
4) npm install elasticdump
5) cd node_modules/elasticdump/bin  后便可以执行操作。

安装后如下所示:

[root@N3 elasticdump]# pwd
/home/tp/node_modules/elasticdump
[root@N3 elasticdump]# ls -al
total 388
drwxr-xr-x 2 root root 4096 Mar 21 15:46 bin
-rw-r--r-- 1 root root 174 Mar 18 2016 Dockerfile
-rw-r--r-- 1 root root 299251 Mar 15 2014 elasticdump.jpg
-rw-r--r-- 1 root root 6172 Feb 2 23:47 elasticdump.js
drwxr-xr-x 2 root root 4096 Jul 13 2016 .github
drwxr-xr-x 3 root root 4096 Mar 21 15:46 lib
-rw-r--r-- 1 root root 11356 May 22 2014 LICENSE.txt
drwxr-xr-x 10 root root 4096 Mar 21 15:46 node_modules
-rw-r--r-- 1 root root 44 May 22 2014 .npmignore
-rw-r--r-- 1 root root 15135 Mar 21 15:46 package.json
-rw-r--r-- 1 root root 13335 Dec 14 06:20 README.md
drwxr-xr-x 3 root root 4096 Mar 21 15:46 test
-rw-r--r-- 1 root root 1150 Dec 2 07:54 .travis.yml

##1.3 elasticsearch-dump 使用

'#拷贝analyzer如分词
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=analyzer
'#拷贝映射
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping
'#拷贝数据
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=data

##1.4 elasticsearch-dump实战小结
源ES版本1.6.0,目标ES版本:2.3.4,验证发现:analyzer和mapping可以拷贝成功。
但是,data拷贝不成功。目标机器ES中不能显示出数据。根本原因没有排查到。

#2、 Elasticsearch-Exporter迁移
##2.1 Elasticsearch-Exporter简介
https://github.com/mallocator/Elasticsearch-Exporter
A small script to export data from one Elasticsearch cluster into another. 将ES中的数据向其他导出的简单脚本实现。

##2.2、Elasticsearch-Exporter安装
http://www.dahouduan.com/2014/12/25/centos-yum-install-nodejs-npm/
centos用 yum 方式安装 nodejs 和 npm

npm install nomnom
npm install colors
npm install elasticsearch-exporter --production

安装后:

[root@N3 elasticsearch-exporter]# ll -ls
total 80
 4 drwxr-xr-x 2 root root 4096 Mar 21 22:01 drivers
12 -rw-r--r-- 1 root root 11523 Sep 19 2014 exporter.js
12 -rw-r--r-- 1 root root 11324 Mar 16 2014 LICENSE
 4 drwxr-xr-x 4 root root 4096 Mar 21 22:01 node_modules
12 -rw-r--r-- 1 root root 11259 Sep 19 2014 options.js
16 -rw-r--r-- 1 root root 14500 Mar 21 22:01 package.json
16 -rw-r--r-- 1 root root 12645 Sep 19 2014 README.md
 4 drwxr-xr-x 2 root root 4096 Apr 25 2014 tools

##2.3、 Elasticsearch-Exporter使用

node exporter.js -a <source hostname> -b <target hostname> -p <s port> -q <t port> -i <s index> -j <t index>

即可实现跨机器索引的迁移。

更多的参数可以查看node exporter.js –help

[root@N3 elasticsearch-exporter]# node exporter.js --help
Elasticsearch Exporter - Version 1.4.0
Usage: exporter [options]
Options:
  -a <hostname>, --sourceHost <hostname>  迁移源机器地址
  -b <hostname>, --targetHost <hostname>  迁移目的机器地址(如果没有设置索引,目的地址需要有别于源地址)
  -p <port>, --sourcePort <port>   源机器的ES的端口,9200(一般)
  -q <port>, --targetPort <port>    目标机器的ES的端口,9200(一般)

  -i <index>, --sourceIndex <index> 源ES待导出的索引,如果该值不设定,整个的数据库都会导出。
  -j <index>, --targetIndex <index>目标机器ES的索引,如果源索引设定,该值必须填写。

##2.4、 Elasticsearch-Exporter 索引迁移实战(验证ok)

[root@No3 elasticsearch-exporter]# node exporter.js -a 10.221.110.31-b 100.0.1.130 -p 9200 -q 9200 -i awppx -j awppx
同步最后会显示:
Number of calls: 169
Fetched Entries: 8064 documents
Processed Entries: 8064 documents
Source DB Size: 8064 documents

代表同步成功。
源ES版本1.6.0,目标ES版本:2.3.4,
验证发现:可以使用 Elasticsearch-Exporter跨机器、跨ES版本同步索引成功。

#3、logstash定向索引迁移

[root@N3 bin]# cat ./logstash_output_mongo/logstash_es22es.conf
input {
  elasticsearch {
  hosts => [ "100.200.10.54:9200" ]
  index => "doc"
  size => 1000
  scroll => "5m"
  docinfo => true
  scan => true
  }
}

filter {
json {
  source => "message"
  remove_field => ["message"]
  }
  mutate {
  # rename field from 'name' to 'browser_name'
  rename => { "_id" => "wid" }
}
}

output {
  elasticsearch {
  hosts => [ "100.20.32.45:9200" ]
  document_type => "docxinfo"
  index => "docx"
  }

  stdout {
  codec => "dots"
  }

}

4、elasticsearch-migration工具

https://github.com/medcl/elasticsearch-migration
支持多个版本间的数据迁移,使用scroll+bulk
1.版本支持1.x,2.x.5.0 (0.x未测试)
2.支持http basic auth 认证的es集群
3.支持导入覆盖索引名称(目前只支持单个索引导入的情况下可指定)
4.支持index setting和mapping的同步(相关es大版本,2.x和5.0之间不支持)
5.支持dump到本地文件
6.支持从dump文件加载导入到指定索引
讨论参考:https://elasticsearch.cn/article/78

5、小结

对比发现, Elasticsearch-Exporter在索引迁移方面相对更好用。(待深入研究补充)
而logstash定向索引用于辅助解决 Elasticsearch-Exporter不同版本迁移有Bug的情形。

参考:
[1]http://blog.csdn.net/u014587343/article/details/50541494
[2]http://stackoverflow.com/questions/26547560/how-to-move-elasticsearch-data-from-one-server-to-another

——————————————————————————————————
更多ES相关实战干货经验分享,请扫描下方【铭毅天下】微信公众号二维码关注。
(每周至少更新一篇!)

这里写图片描述
和你一起,死磕Elasticsearch
——————————————————————————————————

2017年3月23日 21:20 思于家中床前
2018年3月25日 14:55更新第四种方式

作者:铭毅天下
转载请标明出处,原文地址:
http://blog.csdn.net/laoyang360/article/details/65449407
如果感觉本文对您有帮助,请点击‘顶’支持一下,您的支持是我坚持写作最大的动力,谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139674.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【经验总结—2】:深度学习数据集下载网站总结[通俗易懂]

    【经验总结—2】:深度学习数据集下载网站总结[通俗易懂]数据集是深度学习的基础,深度学习模型的好坏与数据集有着直接关联,这里给出一些搜索数据集的优秀网站,记得要一键三连哦!!1.CVDatasetsontheweb一个非常全的数据集总结网站,里面包含了目标检测、目标分类、目标识别、目标跟踪、语义分割、人体姿态数据集等。2.YetAnotherComputerVisionIndexToDatasets(YACVID)全,啥都有!3.阿里天池数据集不得不说,阿里nb!数据集种类丰富,分类明晰!不止如此,阿里每年都

    2022年10月7日
    2
  • 简述mux vlan的功能及应用场景_vlan的原理

    简述mux vlan的功能及应用场景_vlan的原理MuxVLAN是一种在交换机上的2层隔离技术,基于VLAN实现资源的控制。MuxVLAN技术中包含了主VLAN和辅助VLAN;辅助VLAN分为隔离VLAN和组VLAN。一个主VLAN中可以同时包含多个组VLAN,最多只能包含1个隔离VLAN。同一个组VLAN中的端口可以互相通信,不同组VLAN中的端口无法通信;同一个隔离组中的端口不可以通信;但是隔离VLAN与组VLAN中的端口,都可以与主VLAN中的端口进行通信。简述端口隔离的实现原理端口隔离是一种在

    2022年8月10日
    5
  • shell遍历根目录_efi shell 命令中如何返回上级目录和根目录?[通俗易懂]

    shell遍历根目录_efi shell 命令中如何返回上级目录和根目录?[通俗易懂]下面是efishell的帮助信息。你对比看看吧(我看了下,这里的根是\符号)。ThiscommandcdchangesthecurrentworkingdirectorythatisusedbytheEFIShellenvironment.ConventionDescription.Referstothecurrentdir…

    2022年7月24日
    23
  • JRTPLIB 3.9.1文档翻译

    JRTPLIB 3.9.1文档翻译MainPageJRTPLIBAuthor:      JoriLiesenborgs      DevelopedattheTheExpertiseCentreforDigitalMedia(EDM),aresearchinstituteoftheHasseltUniversityAcknowledg

    2022年7月28日
    3
  • vb教程编程实例详解pdf_vb程序设计教程答案刘炳文

    vb教程编程实例详解pdf_vb程序设计教程答案刘炳文实验8-1编写如图2.8.1所示的应用程度。若单击“建立文件”按钮,则分别用Print#和和Write#语句将三个同学的学号、姓名和成绩写入Score.dat和Score1.dat;若单击“读取文件”按钮,则用lineInput语句按行将两个(当前目录)文件中的数据显示在相应的文本框。其中:学号和姓名是字符串类型,成绩是整型。解题,画2个按钮,2个文本框(2个文本框的MultiLin…

    2022年10月6日
    3
  • 关于HeartBleed漏洞的总结「建议收藏」

    关于HeartBleed漏洞的总结「建议收藏」一:前言HeartBleed漏洞又称为心脏出血漏洞,编号(CVE-2014-0160),产生原因:由于未能在memcpy()调用受害用户输入的内容作为长度参数之前正确进行边界检查。攻击者可以追踪OpenSSl所分配的64KB内存,将超出必要范围的字节信息复制到缓存当中,再返回缓存内容,这样一来,受害者的内存内容就会每次泄露64KB.简单来说,这就是OpenSSL缺陷造成的漏洞二:环境…

    2022年7月25日
    16

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号