elasticsearch設(shè)置共享目錄、創(chuàng)建備份、恢復(fù)備份
假設(shè)es集群192.168.0.101、192.168.0.102、192.168.0.103三臺節(jié)點
以下一至六步驟中除第三步只在101上執(zhí)行外,其他步驟所有服務(wù)器都要執(zhí)行
一、安裝nfs服務(wù)
yum install nfs-utils rpcbind -y; #設(shè)置開機自啟動 systemctl enable rpcbind.service systemctl enable nfs-server.service #啟動服務(wù) systemctl start rpcbind.service systemctl start nfs-server.service
二、創(chuàng)建共享目錄
mkdir /data/elastic/bak/backup_es
# 由于備份程序是ES進程進行創(chuàng)建,因此設(shè)置目錄的擁有者為啟動ES程序的用戶 chown -R es:es /data/elastic/bak/backup_es
三、為服務(wù)端修改配置文件
只在192.168.0.101上執(zhí)行
vi /etc/exports
# 添加下面語句 /data/elastic/bak/backup_es *(rw,sync,no_root_squash,no_subtree_check) # 刷新配置使得修改立刻生效 exportfs -a # 查看可掛載目錄 showmount -e 192.168.0.101
四、掛載目錄
將三臺都掛載到同一臺服務(wù)器上
# 查看可掛載目錄 showmount -e 192.168.0.101 # 掛載 mount -t nfs 192.168.0.101:/data/elastic/bak/backup_es /data/elastic/bak/backup_es
五、設(shè)置開機自動掛載
# 查看當前掛載 df -h # 設(shè)置開機自動掛載 vi /etc/fstab 192.168。0.101:/data/elastic/bak/backup_es /data/elastic/bak/backup_es nfs defaults 0 0
六、修改es配置
vim elasticsearch.yml # 在 elasticsearch.yml 中添加下面配置來設(shè)置備份倉庫路徑 path.repo: ["/data/elastic/bak/backup_es"]
七、重啟es
八、創(chuàng)建備份倉庫
POST _snapshot/ backup_es
{
"type": "fs",
"settings": {
"location": "/data/elastic/bak/backup_es",
"max_restore_bytes_per_sec": "100mb",
"max_snapshot_bytes_per_sec": "100mb",
"compress": true
}
}
九、制作備份
POST _snapshot/ backup_es/ship_20191130 #_snapshot/備份倉庫/備份名稱
{
"indices": "t_ship_latlng201911*", #需要備份的索引
"include_global_state": false,
"ignore_unavailable": true
}
查看快照
GET _snapshot/backup_es/_all
十、恢復(fù)備份
# 全部恢復(fù)
POST /_snapshot/backup_es/ship_20191130/_restore
# 恢復(fù)指定的索引
POST /_snapshot/backup_es/ship_20191130/_restore
{
"indices": "t_ship_latlng20191101,t_ship_latlng20191102",
"ignore_unavailable": true,
"include_global_state": false,
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1",
"index_settings": {
"index.number_of_replicas": 0
},
"ignore_index_settings": [
"index.refresh_interval"
]
}
代碼解析詳見:
https://blog.csdn.net/woshixiazaizhe/article/details/83896750
浙公網(wǎng)安備 33010602011771號