这是在ES6.8.7环境进行的
步骤一:提前准备好对象存储,和bukect
"access_key": "xxxxxx"
"secret_key": "xxxxxx"
"bucket":"xxxxxx"
步骤二:设置访问s3账号密码,根据步骤一中准备好的bukect的access_key, secret_key。
#ACCESS-KEY bin/elasticsearch-keystore add s3.client.default.access_key
#SECRET-KEY bin/elasticsearch-keystore add s3.client.default.secret_key
注意:上述命令中的default,可以自定义名称。例如:bin/elasticsearch-keystore add s3.client.ceph-test.secret_key 注意这个可自定义的ceph-test,下面仓库注册步骤中需要用到这个设置值。 这里设置为ceph-test
步骤三:elastcsearch.yml正常不需要进行设置,但是如果搭建的ceph服务不支持https,只支持http访问,则需要在elasticsearch.yml中进行设置s3.client.ceph-test.protocol: "http" 此参数,默认为https 此参数如果不设置,ES服务虽然可正常启动,集群可正常使用,但是在进行快照仓库注册和使用时,会报错。
如果使用docker部署,可通过修改elastcsearch.yml文件对此参数进行设置,也可使用环境变量方式. 如果使用http访问ceph。可以在elasticsearch.yml文件中进行设置,用这种方式设置可能会注册失败,也可以在进行snapshot仓库注册时,进行设置。如下例:
curl -u elastic:xxxx -XPUT localhost:9200/_snapshot/backup -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"client": "ceph", # 这里与上述步骤二中提到的自定义的名称一致
"bucket": "test-backup", ## 已经存在的一个bucket
"protocol": "http",
"endpoint": "192.56.0.162:8080",
"compress":"true",
"base_path": "backup" ## 快照仓库名
}
}'
步骤四:集群中的所有节点(master, data, coo)都需要进行步骤二、三设置,所有节点都需要安装repository-s3插件。
完成以上步骤,集群与ceph的对接算是完成了。下面就可以开始进行仓库注册和数据备份了。每个节点完成上述步骤的设置后,需要重启服务。
步骤五:注册备份仓库
curl -u elastic:xxxx -XPUT localhost:9200/_snapshot/backup -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"client": "ceph", # 这里与上述步骤三中提到的自定义的名称一致
"bucket": "test-backup", ## 已经存在的一个bucket
"protocol": "http",
"endpoint": "192.56.0.162:8080",
"compress":"true",
"base_path": "backup" ## 快照仓库名
}
}'
步骤六:创建快照
curl -u elastic:xxxx -XPUT localhost:9200/_snapshot/backup/test_snapshot_20211115 -H 'Content-Type: application/json' -d'
{
"indices": "*",
"ignore_unavailable": true,
"include_global_state": false
}'
七、备份所有索引数据。curl -u elastic:xxxxx -XPUT localhost:9200/_snapshot/backup/snapshot_all_1
{ "indices": "*", "ignore_unavailable": true, "include_global_state": false }
八、查看所有的快照GET /_snapshot/backup/_all
九、查看当前正在进行的快照信息curl -u elastic:xxxxx -XGET ocalhost:9200/_snapshot/backup/_current
# 删除快照,可终止正在快照的操作
curl -u elastic:xxxxx -XDELETE localhost:9200/_snapshot/backup/snapshot_all_1
十、快照恢复# 指定索引进行 restore
curl -u elastic:xxxxx -XPOST localhost:9200/_snapshot/backup/test_snapshot_20211115/_restore -H 'Content-Type: application/json' -d'
{
"indices": "log_login_202109",
"rename_pattern": "log_login_(.+)",
"rename_replacement": "restored_log_login_$1"
}'
每天定时任务执行快照的脚本,you can do it.



