溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

elasticsearch 索引數(shù)據(jù)快照備份和恢復(fù)

發(fā)布時(shí)間:2020-07-06 14:45:29 來(lái)源:網(wǎng)絡(luò) 閱讀:1229 作者:我不是三爺 欄目:系統(tǒng)運(yùn)維

最近線上的ES集群埋點(diǎn)數(shù)據(jù)量暴漲,機(jī)器的內(nèi)存磁盤(pán)空間眼看就要炸了。但這部分?jǐn)?shù)據(jù)又是冷數(shù)據(jù),現(xiàn)時(shí)不需要查詢(xún),但又不能直接delete,需保留日后數(shù)據(jù)分析。由于前期急于上線,業(yè)務(wù)代碼沒(méi)有合理分配索引按月切割,全年數(shù)據(jù)丟進(jìn)單個(gè)索引,導(dǎo)致單索引數(shù)據(jù)暴漲到100G+
為解決磁盤(pán)空間的瓶頸,針對(duì)不常用的分片數(shù)據(jù),做快照冷存儲(chǔ)。
應(yīng)用場(chǎng)景:
三節(jié)點(diǎn)的ES集群:192.168.85.39 ,192.168.85.36,192.168.85.33

找一臺(tái)有磁盤(pán)空間的服務(wù)器,搭建NFS,用于共享目錄掛載。已192.168.85.63為例

應(yīng)用場(chǎng)景:ES集群三節(jié)點(diǎn) 192.168.85.39,192.168.85.33,192.168.85.36
NFS存儲(chǔ)服務(wù)器:192.168.5.63

一.搭建NFS共享存儲(chǔ)服務(wù)器 (5.63上操作)

1.安裝 nfs服務(wù)  
yum install -y nfs-utils

2. 開(kāi)機(jī)啟動(dòng)
systemctl enable rpcbind.service
systemctl enable nfs-server.service

3.  分別啟動(dòng)rpcbind和nfs服務(wù):
systemctl start rpcbind.service
systemctl start nfs-server.service

4.firewalld 防火墻針對(duì)es節(jié)點(diǎn)內(nèi)網(wǎng)ip開(kāi)放NFS服務(wù)監(jiān)聽(tīng)端口:
111 udp端口    20048 tcp端口    2049 tcp 和 udp全開(kāi)

5.創(chuàng)建本地?cái)?shù)據(jù)共享目錄 并設(shè)置權(quán)限  
mkdir /data/db/elasticsearch/backup
chmod 777 /data/db/elasticsearch/backup
chown -R elasticsearch:elasticsearch /data/db/elasticsearch/backup

6.配置NFS目錄訪問(wèn)權(quán)限
vim etc/exports
/data/db/elasticsearch/backup 192.168.85.39(rw,sync,all_squash)     192.168.85.33(rw,sync,all_squash) 192.168.85.36(rw,sync,all_squash)
exports -r //生效
exports -s //查看

7.es節(jié)點(diǎn)上安裝客戶(hù)端(85.39 85.33 85.36 上操作)
     yum -y install showmount
開(kāi)啟服務(wù):
     systemctl enable rpcbind.service
     systemctl start rpcbind.service
8.創(chuàng)建掛載目錄(85.39 85.33 85.36 上分別操作)
mkdir /mnt/elasticsearch
chmod 777 elasticsearch

掛載共享目錄到本地
mount -t nfs 192.168.5.63:/data/db/elasticsearch/backup  /mnt/elasticsearch

df -h //查看確認(rèn)是否成功掛載

二.創(chuàng)建快照倉(cāng)庫(kù)

curl -XPUT http://192.168.85.39:9002/_snapshot/backup -d'
{
"type": "fs",
"settings": {
"location": "/mnt/elasticsearch/backup",
"compress": true,
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb"
}
}'

備注說(shuō)明:
1.可在es任一節(jié)點(diǎn)操作
2.backup: 指定倉(cāng)庫(kù)名稱(chēng)為backup  ,生成的備份文件存放路徑為/mnt/elasticsearch/backup
3.max_snapshot_bytes_per_sec,max_restore_bytes_per_sec 限定備份和恢復(fù)的數(shù)據(jù)字節(jié)內(nèi)容大小為50mb,
為了防止磁盤(pán)IO過(guò)高。數(shù)值越大,備份恢復(fù)速度越快。50mb為推薦值,IO性能高的機(jī)器可不限制

curl -XPUT http://192.168.85.39:9002/_snapshot/backup -d '
{
    "type": "fs",
    "settings": {
        "location": "/mnt/elasticsearch/backup",
        "compress": true
    }
}'

三.創(chuàng)建快照備份
1.針對(duì)全索引快照備份

curl -XPUT 192.168.85.39:9002/_snapshot/backup/snapshot_all?pretty

備注說(shuō)明:
1.指定備份到倉(cāng)庫(kù)backup
2.快照名稱(chēng)為 snapshot_all

2.針對(duì)指定某個(gè)單獨(dú)索引快照備份(為了區(qū)分不同索引備份目錄,建議倉(cāng)庫(kù)用索引名稱(chēng)命名)

單獨(dú)快照備份user_event_201810這個(gè)索引
2.1先針對(duì)索引創(chuàng)建倉(cāng)庫(kù)
curl -XPUT http://192.168.85.39:9002/_snapshot/user_event_201810 -d'
{
"type": "fs",
"settings": {
"location": "/mnt/elasticsearch/user_event_201810",
"compress": true,
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb"
}
}'

2.2 快照備份索引user_event_201810操作
curl -XPUT http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810?wait_for_completion=true -d '
{
"indices":"user_event_201810",
"ignore_unavailable": "true",
"include_global_state": false
}'

備注說(shuō)明:
1.創(chuàng)建的倉(cāng)庫(kù)名為user_event_201810
2.存放的文件目錄為/mnt/elasticsearch/user_event_201810
3.indices:指定索引源為user_event_201810
4.增加?wait_for_completion=true參數(shù)是為了執(zhí)行完成返回結(jié)果狀態(tài)

四.恢復(fù)快照備份數(shù)據(jù)到es集群
1.針對(duì)全索引快照備份的恢復(fù)操作

curl -XPOST http://192.168.85.39:9200/_snapshot/backup/snapshot_all/_restore

備注說(shuō)明:
1.指定倉(cāng)庫(kù)名稱(chēng)backup
2.指定快照備份名稱(chēng)snapshot_all

2.針對(duì)某個(gè)指定索引的快照備份恢復(fù)操作

針對(duì)索引user_event_201810快照恢復(fù)
curl -XPOST http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810/_restore

備注說(shuō)明:
1.指定倉(cāng)庫(kù)名稱(chēng)user_event_201810
2.指定快照備份名稱(chēng)user_event_201810

五:輔助操作命令
1.查看已存在倉(cāng)庫(kù)

curl 192.168.85.39:9002/_cat/repositories?

2.查看已存在快照

curl -XGET http://192.168.85.39:9002/_snapshot?   //查看全部
curl -XGET http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810//查看指定索引

3.刪除快照

curl -XDELETE http://192.168.85.39:9002/_snapshot/user_event_201810/user_event_201810
//刪除快照user_event_201810

4.刪除倉(cāng)庫(kù)

curl -XDELETE http://192.168.85.39:9002/_snapshot/user_event_201810
//刪除倉(cāng)庫(kù)user_event_201810

elasticsearch其中一節(jié)點(diǎn)配置文件

cluster.name: my-application1
node.name: node-3
path.data: /data/db/elasticsearch
path.logs: /data/log/elasticsearch/logs
path.repo: ["/mnt/elasticsearch"]
network.host: 192.168.85.33
http.port: 9002
transport.tcp.port: 9102
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["192.168.85.39:9102","192.168.85.36:9102","192.168.85.33:9102"]
discovery.zen.minimum_master_nodes: 2
indices.query.bool.max_clause_count: 10240
http.cors.enabled: true
http.cors.allow-origin: "*"

NFS
mount -t nfs 192.168.5.63:/data/db/elasticsearch/backup /mnt/elasticsearch

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI