假设es集群192.168.0.101、192.168.0.102、192.168.0.103三台节点
以下一至六步骤中除第三步只在101上执行外,其他步骤所有服务器都要执行
一、安装nfs服务
yum install nfs-utils rpcbind -y; #设置开机自启动 systemctl enable rpcbind.service systemctl enable nfs-server.service #启动服务 systemctl start rpcbind.service systemctl start nfs-server.service
二、创建共享目录
mkdir /data/elastic/bak/backup_es
# 由于备份程序是ES进程进行创建,因此设置目录的拥有者为启动ES程序的用户 chown -R es:es /data/elastic/bak/backup_es
三、为服务端修改配置文件
只在192.168.0.101上执行
vi /etc/exports
# 添加下面语句 /data/elastic/bak/backup_es *(rw,sync,no_root_squash,no_subtree_check) # 刷新配置使得修改立刻生效 exportfs -a # 查看可挂载目录 showmount -e 192.168.0.101
四、挂载目录
将三台都挂载到同一台服务器上
# 查看可挂载目录 showmount -e 192.168.0.101 # 挂载 mount -t nfs 192.168.0.101:/data/elastic/bak/backup_es /data/elastic/bak/backup_es
五、设置开机自动挂载
# 查看当前挂载 df -h # 设置开机自动挂载 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 中添加下面配置来设置备份仓库路径 path.repo: ["/data/elastic/bak/backup_es"]
七、重启es
八、创建备份仓库
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
十、恢复备份
# 全部恢复
POST /_snapshot/backup_es/ship_20191130/_restore
# 恢复指定的索引
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