記錄一次NFS快照es叢集索引備份
阿新 • • 發佈:2021-01-11
1,環境搭建:
es(主) nfs(客戶端) |
192.168.72.158 |
es(從) nfs(服務端) |
192.168.72.152 |
es(從) nfs(客戶端) |
192.168.72.153 |
關閉防火牆:systemctl stop firewalld 永久關閉防火牆:systemctl disable firewalld 關閉selinux:sentenforce 0 永久關閉selinux
2,搭建、啟動es叢集
3,安裝nfs
連結: https://pan.baidu.com/s/17p1fl7FM9jMEo-yfe_U0KAcd /nfs rpm -ivh —nodeps —force *.rpm 啟動nfs
systemctl start rpcbind.service systemctl start nfs-server.service 開機自啟nfs
systemctl enable rpcbind.service systemctl enable nfs-server.service
4,建立共享目錄
NFS服務端操作
mkdir -p /data/es/backup chown -R elasticsearch.elasticsearch /data/es/backup chmod 755 /data/es/backup vim /etc/exports 追加以下內容 /data/es/backup 192.168.72.158(rw,sync,all_squash) 192.168.72.152(rw,sync,all_squash) 192.168.72.153(rw,sync,all_squash) 立刻生效 exportfs -r 重新掛載 exportfs -v 顯示共享目錄 export -u 表示解除安裝某一個目錄
5, 掛載共享目錄(服務端客戶端都操作)
mount -t nfs -o nolock,nfsvers=3,vers=3 -o proto=tcp 192.168.72.152:/data/es/backup /home/tgram/
6,修改es配置檔案,重啟es叢集
在elasticsearchc.yml中加入一行 path.repo: /home/tgram ./elasticsearch &
7,建立備份倉庫
curl -H "Content-Type: application/json" -XPUT 'http://192.168.72.152:9200/_snapshot/EsBackup_zip' -d '{ > "type": "fs", > "settings": { > "location": "/home/tgram/compress_snapshot", > "compress": true > } > }' [2021-01-04T15:36:45,126][INFO ][o.e.r.RepositoriesService] [node01.tgram.com] put repository [EsBackup_zip] {"acknowledged":true}8,檢視剛建立的倉庫
[root@localhost home]# curl -XGET 'http://192.168.72.152:9200/_snapshot?pretty' { "EsBackup_zip" : { "type" : "fs", "settings" : { "compress" : "true", "location" : "/home/tgram/compress_snapshot" } } }
9,備份指定索引資料
(假設要備份全部索引資料, 則可以:) [root@localhost home]# curl -H "Content-Type: application/json" -XPUT 'http://192.168.72.152:9200/_snapshot/EsBackup_zip/snapshot_all' [2021-01-04T15:54:14,046][INFO ][o.e.s.SnapshotsService ] [node01.tgram.com] snapshot [EsBackup_zip:snapshot_all/8nMl1krVQvaI1VkYLg7fKw] started {"accepted":true}[root@localhost home]# [2021-01-04T15:54:14,125][INFO ][o.e.s.SnapshotsService ] [node01.tgram.com] snapshot [EsBackup_zip:snapshot_all/8nMl1krVQvaI1VkYLg7fKw] completed with state [SUCCESS]
10,恢復整個快照索引
root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XPOST 'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot_all/_restore' {"snapshot":{"snapshot":"snapshot_all","indices":[],"shards":{"total":0,"failed":0,"successful":0}}}
11,檢視恢復狀態
[root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET 'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot_all/_status' {"snapshots":[{"snapshot":"snapshot_all","repository":"EsBackup_zip","uuid":"8nMl1krVQvaI1VkYLg7fKw","state":"SUCCESS","include_global_state":true,"shards_stats":{"initializing":0,"started":0,"finalizing":0,"done":0,"failed":0,"total":0},"stats":{"incremental":{"file_count":0,"size_in_bytes":0},"total":{"file_count":0,"size_in_bytes":0},"start_time_i
12,檢視索引、刪除索引
[root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET 'http://192.168.72.158:9200/_cat/indices?v' health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open commodity 4sUZXNX0SvO3ZbpwlILQ3A 5 1 0 0 2.5kb 1.2kb green open label_11009 0oX0nZU_RK-iflF6filOeg 5 1 1 0 7.7kb 3.8kb [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XDELETE 'http://192.168.72.158:9200/commodity' [2021-01-04T19:20:43,236][INFO ][o.e.c.m.MetaDataDeleteIndexService] [node01.tgram.com] [commodity/4sUZXNX0SvO3ZbpwlILQ3A] deleting index {"acknowledged":true} [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XDELETE 'http://192.168.72.158:9200/label_11009' [2021-01-04T19:21:00,756][INFO ][o.e.c.m.MetaDataDeleteIndexService] [node01.tgram.com] [label_11009/0oX0nZU_RK-iflF6filOeg] deleting index {"acknowledged":true} ###再次檢視發現所以已刪除 [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET 'http://192.168.72.158:9200/_cat/indices?v' health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
13,恢復單個索引
[root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XPOST 'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot2_all/_restore' -d '{ > "indices": "label_11009", > "rename_replacement": "label_22009" > }'
【注】 本文共設計兩個索引commodity、label_11009 兩個快照snapshot_all、snapshot2_all 一個倉庫compress_snapshot snapshot2_all 快照名稱 commodity 原有索引名稱 label_11009原有索引名稱 label_22009恢復單個索引要替換的名稱 偷襲!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! https://blog.moguang.me/2017/10/31/bigdata/es-backup-restore-md/#5-%E6%81%A2%E5%A4%8D%E5%A4%87%E4%BB%BD%E7%B4%A2%E5%BC%95