日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Elasticsearch索引迁移的三种方式

發布時間:2024/9/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 后便可以執行操作。
  • 1
  • 2
  • 3
  • 4
  • 5

安裝后如下所示:

[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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

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
  • 1
  • 2
  • 3

安裝后:

[root@N3 elasticsearch-exporter]# ll -ls total 804 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 LICENSE4 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.md4 drwxr-xr-x 2 root root 4096 Apr 25 2014 tools
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

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>
  • 1

即可實現跨機器索引的遷移。

更多的參數可以查看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的索引,如果源索引設定,該值必須填寫。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

代表同步成功。
源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 => 1000scroll => "5m"docinfo => truescan => 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"}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

4、小結
對比發現, Elasticsearch-Exporter在索引遷移方面相對更好用。(待深入研究補充)
而logstash定向索引用于輔助解決 Elasticsearch-Exporter不同版本遷移有Bug的情形。

來源:http://blog.csdn.net/laoyang360/article/details/65449407

總結

以上是生活随笔為你收集整理的Elasticsearch索引迁移的三种方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。