html購物網(wǎng)站設(shè)計/世界羽聯(lián)最新排名
【Elasticsearch】索引快照并還原到其他集群
前提:es節(jié)點的所有用戶id和組id都需要相同,最好在新建集群時指定用戶id和組id,否則掛載后執(zhí)行curl時會提示權(quán)限報錯。
解決方法(gpt生成),不敢在生產(chǎn)嘗試。
點我
一、安裝共享文件系統(tǒng)
1.啟動nfs
systemctl start nfs rpcbind
2. 編輯nfs文件
vi /etc/exports
/opt/public 192.168.113.0/24(rw,no_root_squash,insecure,sync)
3. 修改共享目錄用戶
比如elasticsearch使用的是es用戶,用戶權(quán)限這里要修改為es
chown es.es /opt/public
查看狀態(tài)
exportfs -rv
查看掛載源
showmount -a
二、ES配置
1.各個節(jié)點掛載共享目錄到repo指定目錄,這里可不重啟es
我這里配置的path.repo
path.repo: /home/elasticsearch-7.9.1/repository
mount -t nfs 192.168.113.101:/opt/public /home/elasticsearch-7.9.1/repository
2. 新建存儲庫
curl -u elastic -H 'Content-type: application/json' -XPUT 'http://192.168.113.101:9200/_snapshot/my_fs_backup' -d '{"type": "fs","settings": {"location": "my_fs_backup_location"}
}'
3. 新建快照(“metrics_38”)
curl -u elastic -H 'Content-type: application/json' -XPUT 'http://192.168.113.101:9200/_snapshot/my_fs_backup/metrics_38?wait_for_completion=true' -d '{"indices": "metrics_38"
}'
可以快照所有索引,使用“-”可以剔除指定的索引index1和index2
{
“indices”: “*,-index1,-index2”
}
4. 查看快照狀態(tài)
curl -u elastic -H ‘Content-type: application/json’ -XGET ‘http://192.168.113.101:9200/_snapshot/my_fs_backup/metrics_38’
5. 后臺查看數(shù)據(jù)
#repo.data: /home/elasticsearch-7.9.1/repository
cd /home/elasticsearch-7.9.1/repository/my_fs_backup_location
du -sh
三、還原到其他ES集群
索引名稱不能沖突。
1. 拷貝文件到path.repo目錄下
2. 在其他上還原es集群上,新建存儲庫
curl -H 'Content-type: application/json' -XPUT 'http://127.0.0.1:9200/_snapshot/my_fs_backup' -d '{"type": "fs","settings": {"location": "my_fs_backup_location"}
}'
4. 還原快照,等待green
curl -H 'Content-type: application/json' -XPOST 'http://127.0.0.1:9200/_snapshot/my_fs_backup/metrics_38/_restore' -d '{"indices": "metrics_38","rename_pattern": "(.+)"
}'
5. 批量還原
curl -H 'Content-type: application/json' -XPOST 'http://192.168.113.195:9200/_snapshot/my_fs_backup/metrics_38/_restore' -d '{"indices": "*","rename_pattern": "(.+)","rename_replacement": "restored-$1"
}'