Elasticsearch-5.6.0使用repository-hdfs快照(備份)數(shù)據(jù)到hdfs并恢復(fù)

背景

Elasticsearch的副本機(jī)制提供了可靠性堪唐,可以容忍個(gè)別節(jié)點(diǎn)丟失而不影響集群的對外服務(wù),但是并不能提供對災(zāi)難性故障的保護(hù)男公,所以需要對ES集群數(shù)據(jù)做一個(gè)完整的備份合陵,以便在災(zāi)難性故障發(fā)生時(shí),能快速恢復(fù)數(shù)據(jù)踏拜。ES官方提供了快照/恢復(fù)(Snapshot/Restore)的方式低剔,支持的插件包括Azure Repository Plugin襟齿、S3 Repository Plugin、Hadoop HDFS Repository Plugin屋摔、Google Cloud Storage Respository Plugin替梨,這里我使用Hadoop HDFS Repository插件,將ES中的數(shù)據(jù)備份到HDFS上弓熏。

  • 說明

本文基于Elasticsearch-5.6.0挽鞠、hadoop-2.6.0-cdh5.7.0狈孔,使用的插件及版本是repository-hdfs-5.6.0.zip,官網(wǎng)地址:
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-snapshots.html
https://www.elastic.co/guide/en/elasticsearch/plugins/5.6/repository-hdfs.html
ES集群快照存在版本兼容性問題嫁赏,請注意:
A snapshot of an index created in 5.x can be restored to 6.x.
A snapshot of an index created in 2.x can be restored to 5.x.
A snapshot of an index created in 1.x can be restored to 2.x.
我的情況是從5.6.0備份數(shù)據(jù)然后恢復(fù)到6.3.2潦蝇,不存在這種兼容性問題。

  • 操作步驟
1. 安裝插件

分別在集群的各個(gè)節(jié)點(diǎn)安裝repository-hdfs插件
在線安裝:sudo bin/elasticsearch-plugin install repository-hdfs
離線安裝:
先wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-hdfs/repository-hdfs-5.6.0.zip
然后bin/elasticsearch-plugin install file:///data/elastic/repository-hdfs-5.6.0.zip

2. 創(chuàng)建倉庫贤牛,并在ES注冊
curl -X PUT "172.16.221.105:9400/_snapshot/es_hdfs_repository" -H 'Content-Type: application/json' -d'
{
"type": "hdfs",
"settings": {
    "uri": "hdfs://golive-master:8020/",
    "path": "elasticsearch/respositories/es_hdfs_repository",
    "conf.dfs.client.read.shortcircuit": "true",
    "conf.dfs.domain.socket.path": "/var/lib/hadoop-hdfs/dn_socket"
     }
}
'

創(chuàng)建過程中遇到Permission denied的問題殉簸,我暫時(shí)關(guān)閉了hdfs權(quán)限堤魁,即修改hadoop各節(jié)點(diǎn)hdfs-site.xml,添加如下配置:

<property> 
    <name>dfs.permissions</name> 
    <value>false</value>
</property>

然后重啟hdfs椭微,再次執(zhí)行上述創(chuàng)建倉庫命令即可成功創(chuàng)建蝇率,查看hdfs目錄如下:


hdfs_dir

可以通過如下命令查看倉庫:
curl -X GET "172.16.221.104:9400/_snapshot/es_hdfs_repository"
返回結(jié)果如下:

{
"es_hdfs_repository": {
"type": "hdfs",
"settings": {
"path": "elasticsearch/respositories/es_hdfs_repository",
"uri": "hdfs://golive-master:8020/",
"conf": {
"dfs": {
"client": {
"read": {
"shortcircuit": "true"
}
},
"domain": {
"socket": {
"path": "/var/lib/hadoop-hdfs/dn_socket"
           }
          }
        }
      }
    }
  }
}
3. 創(chuàng)建快照

為所有索引創(chuàng)建快照:

curl -X PUT "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1?wait_for_completion=true" -H 'Content-Type: application/json' -d'
{
"indices": "*"
}
'

通常你會(huì)希望你的快照作為后臺(tái)進(jìn)程運(yùn)行本慕,不過有時(shí)候你會(huì)希望在你的腳本中一直等待到完成侧漓。這可以通過添加一個(gè) wait_for_completion 標(biāo)記實(shí)現(xiàn):wait_for_completion=true布蔗,這個(gè)會(huì)阻塞調(diào)用直到快照完成。注意大型快照會(huì)花很長時(shí)間才返回顿乒。
https://www.elastic.co/guide/cn/elasticsearch/guide/current/backing-up-your-cluster.html

4.恢復(fù)快照

curl -X POST "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1/_restore"
和快照類似泽谨, restore 命令也會(huì)立刻返回,恢復(fù)進(jìn)程會(huì)在后臺(tái)進(jìn)行骨杂。如果你更希望你的 HTTP 調(diào)用阻塞直到恢復(fù)完成腊脱,添加 wait_for_completion 標(biāo)記:

curl -X POST "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1/_restore?wait_for_completion=true"

我恢復(fù)的時(shí)候是恢復(fù)到一個(gè)新的集群(6.3.2的一個(gè)集群)龙亲,因?yàn)闆]有在es注冊HDFS倉庫的位置,報(bào)錯(cuò)說找不到倉庫杜耙,于是又通過創(chuàng)建倉庫的命令注冊了一下拂盯,再執(zhí)行恢復(fù)命令就好了谈竿,這一點(diǎn)官方是這么說的:

All that is required is registering the repository containing the snapshot in the new cluster and starting the >restore process.

英文文檔:https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
中文文檔:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_restoring_from_a_snapshot.html

5.獲取快照信息和狀態(tài)

獲取一個(gè)倉庫中所有快照的完整列表空凸,使用 _all 占位符替換掉具體的快照名稱:
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/_all"
獲取一個(gè)快照的詳細(xì)信息:
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_2"
獲取一個(gè)快照更詳細(xì)的信息:
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_2/_status"
官方文檔:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/backing-up-your-cluster.html
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-snapshots.html

  • 附錄:

以下是我當(dāng)時(shí)備份/恢復(fù)數(shù)據(jù)用到的相關(guān)命令:

wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-hdfs/repository-hdfs-5.6.0.zip
elasticsearch-5.6.0/bin/elasticsearch-plugin install file:///data/elastic/repository-hdfs-5.6.0.zip

curl 172.16.221.104:9400/_cat/indices?v
curl 172.16.221.104:9400/_cat/master?v
curl 172.16.221.104:9400/_cat/master?help
curl -X PUT "172.16.221.105:9400/_snapshot/es_hdfs_repository" -H 'Content-Type: application/json' -d'
{
"type": "hdfs",
"settings": {
"uri": "hdfs://golive-master:8020/",
"path": "elasticsearch/respositories/es_hdfs_repository",
"conf.dfs.client.read.shortcircuit": "true",
"conf.dfs.domain.socket.path": "/var/lib/hadoop-hdfs/dn_socket"
}
}
'
curl -X PUT "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1?wait_for_completion=true" -H 'Content-Type: application/json' -d'
{
"indices": "*"
}
'
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository"
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1/_status"

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.2/elasticsearch-analysis-ik-6.3.2.zip

[https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-hdfs/repository-hdfs-6.3.2.zip](https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-hdfs/repository-hdfs-6.3.2.zip)

bin/elasticsearch-plugin install file:///data/elastic/repository-hdfs-6.3.2.zip
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_2/_status"
curl 172.16.221.105:9400/_cat/master
curl 172.16.221.12:9400/_cat/nodes
curl -X POST "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_1/_restore"
curl -X POST "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_2/_restore" -H 'Content-Type: application/json' -d'
{
"indices": "a*,l*,m*,u*,i*"
}
'

[https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz](https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz)
curl -X DELETE "172.16.221.105:9400/.kibana-6"
curl -X GET "172.16.221.105:9400/_cat/indices"
curl -X GET "172.16.221.105:9400/_snapshot/es_hdfs_repository/snapshot_2/_status"
curl -X POST "172.16.221.105:9400/a*,l*,m*,u*,i*/_close"
curl -X POST "172.16.221.105:9400/a*,l*,m*,u*,i*/_open"
curl -X GET http://172.16.221.105:9400/ad_base?pretty
curl -X GET http://172.16.221.105:9400/_cluster/health?pretty
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市道逗,隨后出現(xiàn)的幾起案子滓窍,更是在濱河造成了極大的恐慌,老刑警劉巖此蜈,帶你破解...
    沈念sama閱讀 222,104評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件舶替,死亡現(xiàn)場離奇詭異杠园,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)陈醒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,816評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門钉跷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來肚逸,“玉大人彬坏,你說我怎么就攤上這事膝晾。” “怎么了幻赚?”我有些...
    開封第一講書人閱讀 168,697評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵落恼,是天一觀的道長离熏。 經(jīng)常有香客問我撤奸,道長,這世上最難降的妖魔是什么胧瓜? 我笑而不...
    開封第一講書人閱讀 59,836評(píng)論 1 298
  • 正文 為了忘掉前任府喳,我火速辦了婚禮蒲肋,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘钝满。我一直安慰自己兜粘,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,851評(píng)論 6 397
  • 文/花漫 我一把揭開白布弯蚜。 她就那樣靜靜地躺著孔轴,像睡著了一般。 火紅的嫁衣襯著肌膚如雪碎捺。 梳的紋絲不亂的頭發(fā)上路鹰,一...
    開封第一講書人閱讀 52,441評(píng)論 1 310
  • 那天,我揣著相機(jī)與錄音收厨,去河邊找鬼。 笑死诵叁,一個(gè)胖子當(dāng)著我的面吹牛雁竞,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播拧额,決...
    沈念sama閱讀 40,992評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼碑诉,長吁一口氣:“原來是場噩夢啊……” “哼彪腔!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起联贩,我...
    開封第一講書人閱讀 39,899評(píng)論 0 276
  • 序言:老撾萬榮一對情侶失蹤漫仆,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后泪幌,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,457評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡署照,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,529評(píng)論 3 341
  • 正文 我和宋清朗相戀三年祸泪,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片建芙。...
    茶點(diǎn)故事閱讀 40,664評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡没隘,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出禁荸,到底是詐尸還是另有隱情右蒲,我是刑警寧澤,帶...
    沈念sama閱讀 36,346評(píng)論 5 350
  • 正文 年R本政府宣布赶熟,位于F島的核電站瑰妄,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏映砖。R本人自食惡果不足惜间坐,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,025評(píng)論 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望邑退。 院中可真熱鬧竹宋,春花似錦、人聲如沸地技。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,511評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽莫矗。三九已至飒硅,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間趣苏,已是汗流浹背狡相。 一陣腳步聲響...
    開封第一講書人閱讀 33,611評(píng)論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留食磕,地道東北人尽棕。 一個(gè)月前我還...
    沈念sama閱讀 49,081評(píng)論 3 377
  • 正文 我出身青樓,卻偏偏與公主長得像彬伦,于是被迫代替她去往敵國和親滔悉。 傳聞我的和親對象是個(gè)殘疾皇子伊诵,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,675評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 常見的數(shù)據(jù)庫都會(huì)提供備份的機(jī)制,以解決在數(shù)據(jù)庫無法使用的情況下回官,可以開啟新的實(shí)例曹宴,然后通過備份來恢復(fù)數(shù)據(jù)減少損失。...
    rockybean閱讀 1,457評(píng)論 0 2
  • 我們的系統(tǒng)中大部分都是時(shí)序數(shù)據(jù)歉提,一些數(shù)據(jù)被清洗后笛坦,過期的數(shù)據(jù)意義已經(jīng)不大,但是保不齊哪天需要重新清洗或者查閱歷史苔巨,...
    RomainXie閱讀 6,678評(píng)論 0 1
  • 隨筆一畫版扩,驀然驚悚?Σ( °嚇°|||)︴
    Believber閱讀 265評(píng)論 0 0
  • 我十歲那年侄泽,螞蟻給我留下了深刻得啟示礁芦。 那一年,我出于好奇悼尾,用泥土把一個(gè)螞蟻洞埋了起來柿扣。正在我得意時(shí),去外邊覓食的...
    仇河壬閱讀 190評(píng)論 0 0
  • 昨晚女兒再三和我確定闺魏, 媽媽未状,明天我要吃披薩和雞翅! 好的舷胜! 你如果不說話算話娩践,我就不理你們了。 那我和爸爸離家出...
    飛芒果閱讀 234評(píng)論 0 0