配置ElasticSearch支持对象存储备份

温馨提醒

1.1 前提条件

对象存储创建 bucket,获取 AK 和 SK

1.2 安装 s3 插件

1
/usr/share/elasticsearch/bin/elasticsearch-plugin install repository-s3

1.3 配置 s3 访问权限

1
2
/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.access_key
/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.secret_key

1

1.4 配置 ElasticSearch

vim /etc/elasticsearch/elasticsearch.yml

1
2
s3.client.default.endpoint: http://backup-bucket.jzzx.stor.oss.ztcloud:80
s3.client.default.protocol: http

1.5 重启 ElasticSearch 服务

1
systemctl enable --now elasticsearch

1.6 创建快照仓库

1
curl -s -u elastic:123456 -w "\n%{http_code}" -X PUT "http://localhost:9200/_snapshot/${仓库名}" -H 'Content-Type: application/json' -d '{ "type": "s3", "settings": { "bucket": "backup-bucket", "endpoint": "http://s3.xxx.com", "base_path": "elasticsearch", "compress": true, "max_snapshot_bytes_per_sec": "50mb" } }'

1.7 验证存储库

1
curl -u elastic:123456 -X POST "http://localhost:9200/_snapshot/${仓库名}/_verify"

1.8 创建快照

1
curl -s -u elastic:123456 -w "\n%{http_code}" -X PUT "http://localhost:9200/_snapshot/${仓库名}/${快照名}?wait_for_completion=true" -H 'Content-Type: application/json' -d "{ "indices": "${index}", "ignore_unavailable": true, "include_global_state": false }"

1.9 验证备份

1
curl -u elastic:123456 -XGET http://localhost:9200/_snapshot/${仓库名}/_all?pretty

1.10 恢复

1
curl -u elastic:123456 -XPOST http://localhost:9200/_snapshot/${仓库名}/${快照名}/_restore