文章目录
Snapshot And Restore
- Snapshot And Restore
- Hadoop HDFS Repository Plugin
- 使用前提
- 查看插件
- 创建仓库
- 查看仓库
- 创建快照
- 查看快照进度
- 恢复快照
- 查看快照的状态
- 删除快照
- 跨集群使用
快照和恢复有以下作用
- 数据的备份
- 数据的迁移
- 版本升级
- …
下面介绍利用HDFS实现快照和恢复
Hadoop HDFS Repository Plugin使用repository-hdfs插件,可以实现将ES的索引的快照数据写入HDFS和从HDFS上的ES快照中恢复索引数据。
使用前提- ES集群的每一个节点上都安装了
repository-hdfs
插件 - ES节点在启动的时候加载了
repository-hdfs
插件的plugin-security.policy
权限。5.X版本可以在jvm.options
配置文件中新增内容:-Djava.security.policy=file:///{path}/plugin-security.policy
,{path}为到插件repository-hdfs在服务器上的绝对路径。6.X版本后,不需要配置这个了 - 在HDFS中新建用户,与启动es进程的Linux用户名相同。并对相应的HDFS路径进行读写授权。
验证是否安装了repository-hdfs
插件。
GET /_cat/plugins?v
创建仓库
PUT _snapshot/repository1
{
"type": "hdfs",
"settings": {
"uri": "hdfs://127.0.0.1:9000/",
"path": "elasticsearch/repositories/repository1",
"compress": "true",
"max_restore_bytes_per_sec": "40mb",
"max_snapshot_bytes_per_sec": "40mb"
}
}
查看仓库
看是否存在hdfs类型的快照仓库。
GET /_cat/repositories
查看仓库配置,可以看到HDFS仓库的一些配置,比如:HDFS地址,是否压缩,创建快照的速率,恢复的速率等。
GET _snapshot/repository1
查询结果
{
"repository1": {
"type": "hdfs",
"settings": {
"path": "elasticsearch/repositories/repository1",
"max_restore_bytes_per_sec": "40mb",
"compress": "true",
"uri": "hdfs://127.0.0.1:9000",
"max_snapshot_bytes_per_sec": "40mb"
}
}
}
创建快照
PUT /_snapshot/repository1/snapshot-20211214-001
{
"indices": "indexName1,indexName2",
"ignore_unavailable": false,
"include_global_state": true,
"partial": false
}
查看快照进度
GET /_cat/snapshots/repository1?v&s=id
恢复快照
在恢复快照时可以进行索引名称的修改
POST /_snapshot/repository1/snapshot-20211214-001/_restore
{
"indices": "index_1,index_2",
"ignore_unavailable": true,
"include_global_state": true,
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
在恢复快照的时候可以对索引的一些配置进行重新设置。
POST /_snapshot/repository1/snapshot-20211214-001/_restore
{
"indices": "indexName1,indexName2",
"index_settings": {
"index.number_of_replicas": 0
},
"ignore_index_settings": [
"index.refresh_interval"
]
}
查看快照的状态
GET /_snapshot/repository1/snapshot-20211214-001,snapshot_1/_status
删除快照
DELETE /_snapshot/repository1/snapshot-20211214-001
跨集群使用
当需要跨集群实现快照和恢复的时候,在各自的集群中创建同样的仓库,使用相同的HDFS配置即可。