集群使用sanpshot快照需要共享文件系统,所以要先配置个nfs
####elastichsearch配置 实验使用1.6的elasticsearch,发现需要在master的elasticsearch.yml中添加path.repo:/data/app/snapshot后重启es后才能创建仓库
####安装nfs
# yum install nfs-utils -y
# mkdir /data/app/es_snapshot
# vi /etc/exports
/data/app/es_snapshot 192.168.10.*(rw,sync,no_root_squash)
# setenforce 0
# service rpcbind start
# service nfs start
####所有es挂载nfs
# mkdir -p /data/app/snapshot
# yum install nfs-utils -y
# mount 192.168.10.94:/data/app/es_snapshot/ /data/app/snapshot/
####开启快照
- 查看快照仓库
快照仓库为空
# curl http://192.168.10.91:9200/_snapshot/
{}
- 创建快照,设置快照目录
# curl -XPUT http://192.168.10.91:9200/_snapshot/snapshot1 -d '{"type":"fs","settings":{"location":"/data/app/snapshot/","compress":"true"}}'
{"acknowledged":true}
- 再次查询仓库
# curl http://192.168.10.91:9200/_snapshot/
{"snapshot1":{"type":"fs","settings":{"compress":"true","location":"/data/app/snapshot/"}}}
- 快照备份
# curl -XPUT http://192.168.10.91:9200/_snapshot/snapshot1/backup1?wait_for_completion=true #等待快照完成后返回
{"snapshot":{"snapshot":"backup1","indices":["index1","index2"],"state":"SUCCESS","start_time":"2016-04-14T14:21:41.094Z","start_time_in_millis":1460643701094,"end_time":"2016-04-14T14:21:41.545Z","end_time_in_millis":1460643701545,"duration_in_millis":451,"failures":[],"shards":{"total":10,"failed":0,"successful":10}}}
- 查看快照
# curl http://192.168.10.91:9200/_snapshot/snapshot1/_all?pretty=true
"snapshots" : [ {
"snapshot" : "backup1",
"indices" : [ "index1", "index2" ],
"state" : "SUCCESS",
"start_time" : "2016-04-14T14:21:41.094Z",
"start_time_in_millis" : 1460643701094,
"end_time" : "2016-04-14T14:21:41.545Z",
"end_time_in_millis" : 1460643701545,
"duration_in_millis" : 451,
"failures" : [ ],
"shards" : {
"total" : 10,
"failed" : 0,
"successful" : 10
}
}, {
"snapshot" : "backup2",
"indices" : [ "index1", "index2" ],
"state" : "SUCCESS",
"start_time" : "2016-04-14T14:22:02.182Z",
"start_time_in_millis" : 1460643722182,
"end_time" : "2016-04-14T14:22:02.366Z",
"end_time_in_millis" : 1460643722366,
"duration_in_millis" : 184,
"failures" : [ ],
"shards" : {
"total" : 10,
"failed" : 0,
"successful" : 10
}
} ]
}
- 删除快照
# curl -XDELETE http://192.168.10.91:9200/_snapshot/snapshot1/backup1
{"acknowledged":true}
- 从快照恢复
# curl -XDELETE http://192.168.10.91:9200/* 删除重名的index,不然恢复会报错
# curl -XPOST http://192.168.10.91:9200/_snapshot/snapshot1/backup2/_restore?wait_for_completion=true #恢复
{"snapshot":{"snapshot":"backup2","indices":["index1","index2"],"shards":{"total":10,"failed":0,"successful":10}}}