亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

ElasticSearch索引跨集群遷移

不知名網(wǎng)友 / 4235人閱讀
ElasticSearch索引跨集群遷移

點(diǎn)擊上方“IT那活兒”公眾號(hào),關(guān)注后了解更多內(nèi)容,不管IT什么活兒,干就完了?。?!

單索引跨集群遷移:_reindex方式

_reindex方式可將索引數(shù)據(jù)直接從源ES集群導(dǎo)入到新ES集群。
1. 集群環(huán)境
源ES集群地址:xxx.x.xxx.65:9201
新ES集群地址:xxx.x.xxx.214:9201
2. 遷移目標(biāo)
將索引shsnc-crm_tpt_tj_dtfjzl_data遷移至新ES集群,索引中包含10個(gè)文檔。
3. 新ES集群添加白名單并重啟
1)在新ES集群添加白名單允許源集群reindex
2)添加白名單后重啟新ES集群
jps|grep -i elasticsearch|awk {print $1}|xargs kill –-停止新ES集群各節(jié)點(diǎn)
./elasticsearch -d --啟動(dòng)新ES集群各節(jié)點(diǎn)
4. 創(chuàng)建索引并設(shè)置mapping
1)從源ES集群中導(dǎo)出索引模板template_ shsnc-crm_tpt_tj _dtfjzl_data
curl -u xxx.x.xxx.65:9201/_template/template_ shsnc-crm_tpt_tj* >> template.txt
2)在新ES集群中導(dǎo)入索引模板template_ shsnc-crm_tpt_tj _dtfjzl_data
curl -H "Content-Type: application/json"
-XPUT http://xxx.x.XXX.214:9201/_template/template_shsnc-
crm_tpt_tj_dtfjzl_data -d{"order": 0, "index_patterns":
["shsnc-crm_tpt_tj_dtfjzl_data"], "settings": {"index":
{"number_of_shards": "1", "number_of_replicas": "0"}},
"mappings": {"_doc":{"dynamic": false, "properties":
{"appname": {"ignore_above": 10000, "type": "keyword"},
"createTime": {"format": "yyyy-MM-dd HH:mm:ss.SSS", "type": "date"}, "raw_message": {"analyzer": "ik_smart", "type":
"text"}, "startLine": {"ignore_above": 10000, "type":
"keyword"}, "op_time": {"format": "yyyy-MM-dd HH:mm:ss", "type": "date"}, "COUNT": {"ignore_above": 10000, "type":
"keyword"}, "cmdb_id": {"ignore_above": 10000, "type":
"keyword"}, "agentip": {"ignore_above": 10000, "type":
"keyword"}}}}, "aliases": {}}



5. 從源ES集群中reindex數(shù)據(jù)到新ES集群
注:為確保數(shù)據(jù)的完整性源ES集群需停止數(shù)據(jù)寫入。
1)在新ES集群上運(yùn)行如下命令
curl -H Content-Type: application/json
-XPOST "http://xxx.x.xxx.214:9201/_reindex?pretty" -d {
"source": {
"remote": {"host": "http://xxx.x.xxx.65:9201"},
"username": "xxxxxx", --username、password若有則指定,若無(wú)則去掉此項(xiàng)
"password": "xxxxxx",
"index": "shsnc-crm_tpt_tj_dtfjzl_data",
"type": "_doc"},
"dest": {"index": "shsnc-crm_tpt_tj_dtfjzl_data"}}
2)執(zhí)行以上命令后,索引shsnc-crm_tpt_tj_dtfjzl_data的10個(gè)文檔數(shù)據(jù)成功導(dǎo)入到新ES集群

全部索引跨集群遷移:_snapshot方式

_snapshot是Elasticsearch提供的用于對(duì)數(shù)據(jù)進(jìn)行備份和恢復(fù)的接口,即從源ES集群創(chuàng)建數(shù)據(jù)快照,再將快照復(fù)制到目標(biāo)集群進(jìn)行恢復(fù)。
1. 集群環(huán)境
源ES集群地址:xxx.x.xxx.65:9201
新ES集群地址:xxx.x.xxx.20:9201
2. 遷移目標(biāo)
將源ES集群全部索引遷移至新ES集群,主要是紅色框中的4個(gè)索引。
3. 在源集群中創(chuàng)建repository和snapshot
1)快照文件存放repositor倉(cāng)庫(kù)中,一個(gè)repositor倉(cāng)庫(kù)可以存放多個(gè)快照文件,repository支持多種類型,此處以fs類型來(lái)創(chuàng)建repository倉(cāng)庫(kù),即將快照文件存放在文件系統(tǒng)中。
如下,在源ES集群的Elasticsearch.yml配置文件中設(shè)置repository路徑,提前創(chuàng)建“/home/elk/es-repo-test”目錄,添加配置后需要重啟源ES集群。
2)創(chuàng)建repository
curl -H Content-Type: application/json
-XPUT http://xxx.x.xxx.65:9201/_snapshot/my_backup -d {
"type": "fs",
"settings": {
"location": "/home/elk/es-repo-test",
"compress": true,
"max_snapshot_bytes_per_sec":"20mb",
"max_restore_bytes_per_sec":"20mb"}}

注:

  • max_snapshot_bytes_per_se:快照數(shù)據(jù)進(jìn)入倉(cāng)庫(kù)時(shí),限流每秒20mb;
  • max_restore_bytes_per_sec:從倉(cāng)庫(kù)恢復(fù)數(shù)據(jù)時(shí),限流每秒20mb。
3)創(chuàng)建snapshot,快照名稱需小寫,否則報(bào)錯(cuò)(version:6.4.0)
Curl -H Content-Type: application/json -XPUT
http://xxx.x.xxx.65:9201/_snapshot/my_backup/es-snapshot-1?wait_for_completion=true
進(jìn)入快照存放的目錄,查看快照文件:
4. 在新集群中創(chuàng)建repository,并復(fù)制源集群中的snapshot文件
1)在新集群的elasticsearch.yml配置文件中設(shè)置repository路徑,提前創(chuàng)建“/home/elk/es-repo-test”目錄,添加配置后需要重啟新ES集群
2)在新集群中創(chuàng)建repostory
curl -H Content-Type: application/json
-XPUT http://xxx.x.xxx.20:9201/_snapshot/my_backup -d {
"type": "fs",
"settings": {
"location": "/home/elk/es-repo-test",
"compress": true,
"max_snapshot_bytes_per_sec":"20mb",
"max_restore_bytes_per_sec":"20mb"}}
3)復(fù)制源集群中的snapshot文件到新集群
4. 在新集群中通過(guò)快照文件恢復(fù)索引
1)從源集群導(dǎo)入索引模板到目標(biāo)集群
2)在新集群中恢復(fù)索引
curl -XPOST http://xxx.x.xxx.20:9201/_snapshot/my_backup/es-snapshot-1/_restore
3)新集群中查看索引恢復(fù)的狀態(tài)
附:提升數(shù)據(jù)同步的技巧
1)默認(rèn)情況下reindex使用1000進(jìn)行批量操作,可在source中修改size以提升批量寫入。
2)針對(duì)數(shù)據(jù)量比較大的索引,可以在遷移前將目標(biāo)索引的副本數(shù)設(shè)置為0,刷新時(shí)間為-1(-1為不刷新),可加快數(shù)據(jù)同步速度,數(shù)據(jù)遷移完成后再改回。
3)reindex支持使用sliced scroll功能以提升數(shù)據(jù)寫入的效率,sliced scroll以并行化來(lái)重建索引,每個(gè)scroll 請(qǐng)求可以分解成多個(gè)slice請(qǐng)求,各個(gè)slice對(duì)立并行運(yùn)行,寫入效率要快很多倍
Slices可手動(dòng)設(shè)置(slices=3),也可自動(dòng)設(shè)置(slices=auto)。設(shè)置為auto時(shí),對(duì)于單索引,slices等于分片數(shù);針對(duì)多索引,slices等于分片的最小值。Slices等于分片數(shù)時(shí),查詢性能最高效;slices大于分片數(shù)時(shí),不僅不會(huì)提升效率,反而會(huì)增加額外的開(kāi)銷。


本文作者:方 威(上海新炬中北團(tuán)隊(duì))

本文來(lái)源:“IT那活兒”公眾號(hào)

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/129098.html

相關(guān)文章

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<