环境说明
minio 最新版
elasticsearch 7.9
1. docker部署minio对象存储服务
# 单机版docker-compose.yml
version: '3'
services:
minio:
image: minio/minio
hostname: "minio"
ports:
- 9000:9000 # api 端口
- 9001:9001 # 控制台端口
environment:
MINIO_ROOT_USER: admin #管理后台用户名
MINIO_ROOT_PASSWORD: admin123 #管理后台密码,最小8个字符
volumes:
- /docker/minio/data:/data #映射当前目录下的data目录至容器内/data目录
- /docker/minio/config:/root/.minio/ #映射配置目录
- /etc/localtime:/etc/localtime:ro
command: server --console-address ':9001' /data #指定容器中的目录 /data
privileged: true
restart: always
docker-compose up -d
docker-compose ps
访问minio web:http://ip:9001 ,创建用户和桶,示例如下:
minio_username: elasticsearch
minio_password: XuGPEJWH2Hg9CixejOAkXpu0d
minio_bucket: es-bucket
2. elasticsearch安装s3插件并配置
# 在线安装插件
elasticsearch-plugin install repository-s3
# 设置访问minio的信息
elasticsearch-keystore add s3.client.default.access_key #输入elasticsearch
elasticsearch-keystore add s3.client.default.secret_key #输入XuGPEJWH2Hg9CixejOAkXpu0d
# 配置elasticsearch.yml
s3.client.default.endpoint: 192.168.100.100:9000
s3.client.default.protocol: http
重启ES服务
3. elasticsearch配置快照仓库并测试验证
# 配置快照仓库
PUT _snapshot/my_backup
{
"type":"s3",
"settings":{
"bucket":"es-bucket",
"protocol":"http",
"disable_chunked_encoding":"true",
"endpoint":"192.168.100.100:9000"
}
}
# 备份所有索引
PUT _snapshot/my_backup/test1?wait_for_completion=true&pretty
# 查看所有备份
GET _snapshot/my_backup/_all?pretty
# 删除快照
DELETE _snapshot/my_backup/snapshot_2
注意:
用 API 删除快照很重要,而不能用其他机制(比如手动删除,或者用 S3 上的自动清除工具)。因为快照是增量的,有可能很多快照依赖于过去的段。delete API 知道哪些数据还在被更多近期快照使用,然后会只删除不再被使用的段。
但是,如果你做了一次人工文件删除,你将会面临备份严重损坏的风险,因为你在删除的是可能还在使用中的数据。
------------------------------其他命令参考
#备份所有索引
curl -XPUT http:///localhost:9200/_snapshot/backup/snapshot_all
#备份部分索引
curl -XPUT 'http://localhost:9200/_snapshot/backup/index-201807' -H 'Content-Type: application/json' -d '{ "indices": "index-201807" }'
备份多个索引:
{
"indices": "products,index_1,index_2",
"ignore_unavailable": true,
"include_global_state": false
}
#查看快照信息
curl -XGET 'http://localhost:9200/_snapshot/backup/_all'?pretty
#恢复索引数据:
curl -XPOST 'http://localhost:9200/_snapshot/backup/index-201807/_restore
#查看恢复状态:
GET http://localhost:9200/_recovery/index-201807
GET http://localhost:9200/_recovery/
#删除一个快照存储桶:
curl -XDELETE localhost:9200/_snapshot/backup/index-201807?pretty
# 查看所有的仓库
GET /_snapshot/_all
# 查看某一个具体的仓库的快照情况
GET /_snapshot/es_s3_repository/_all?pretty
# 列出所有当前正在运行的快照以及显示他们的详细状态信息
GET /_snapshot/_status?pretty
# 列出所有当前正在运行的快照以及显示他们的详细状态信息
GET /_snapshot/es_s3_repository/_status?pretty
# 查看指定快照的详细状态信息即使不是正在运行
GET /_snapshot/es_s3_repository/snapshot_2/_status?pretty
#删除某一个快照
DELETE /_snapshot/es_s3_repository/snapshot_2
----------------------------
# 推荐的s3权限,如有疑问可以移步官网:https://www.elastic.co/guide/en/elasticsearch/plugins/6.5/repository-s3-repository.html{
"Statement": [
{
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads",
"s3:ListBucketVersions"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::snap.example.com"
]
},
{
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::snap.example.com/*"
]
}
],
"Version": "2012-10-17"
}