ES备份快照到hdfs

Elasticsearch 副本提供了高可靠性,可以容忍节点丢失而不会中断服务。但是,副本并不提供对灾难性故障的保护。对这种情况,你需要的是对集群真正的备份——在某些东西确实出问题的时候有一个完整的拷贝。

通过快照的方式,将Elasticsearch集群中的数据,备份到HDFS上,这样数据即存在于Elasticsearch(简称ES)集群当中,又存在于HDFS上。当ES集群出现不可恢复性的故障时,可以将数据从HDFS上快速恢复。

ES集群快照存在版本兼容性问题:https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html

安装插件

1.命令安装,但是网不好会很惨的

bin/elasticsearch-plugin install repository-hdfs

2.下载好的zip包,安装

参考链接:https://www.elastic.co/guide/en/elasticsearch/plugins/7.9/repository-hdfs.html

下载:https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-hdfs/repository-hdfs-7.9.1.zip.

执行命令

bin/elasticsearch-plugin install file:///home/hadoop/elk/es-reporitory.zip

执行结果,期间输入选项(Continue with installation? [y/N]y)为y即可。

-> Installing file:///opt/server/elasticsearch-7.8.1/repository-hdfs-7.8.1.zip
-> Downloading file:///opt/server/elasticsearch-7.8.1/repository-hdfs-7.8.1.zip
[=================================================] 100%   
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessClassInPackage.sun.security.krb5
* java.lang.RuntimePermission accessDeclaredMembers
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission loadLibrary.jaas
* java.lang.RuntimePermission loadLibrary.jaas_nt
* java.lang.RuntimePermission loadLibrary.jaas_unix
* java.lang.RuntimePermission setContextClassLoader
* java.lang.RuntimePermission shutdownHooks
* java.lang.reflect.ReflectPermission suppressAccessChecks
* java.net.SocketPermission * connect,resolve
* java.net.SocketPermission localhost:0 listen,resolve
* java.security.SecurityPermission insertProvider.SaslPlainServer
* java.security.SecurityPermission putProviderProperty.SaslPlainServer
* java.util.PropertyPermission * read,write
* javax.security.auth.AuthPermission doAs
* javax.security.auth.AuthPermission getSubject
* javax.security.auth.AuthPermission modifyPrincipals
* javax.security.auth.AuthPermission modifyPrivateCredentials
* javax.security.auth.AuthPermission modifyPublicCredentials
* javax.security.auth.PrivateCredentialPermission javax.security.auth.kerberos.KerberosTicket * "*" read
* javax.security.auth.PrivateCredentialPermission javax.security.auth.kerberos.KeyTab * "*" read
* javax.security.auth.PrivateCredentialPermission org.apache.hadoop.security.Credentials * "*" read
* javax.security.auth.kerberos.ServicePermission * initiate
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed repository-hdfs

安装成功后,在 Elasticsearch 安装目录下的plugins目录下,新增一个名为repository-hdfs的目录

创建备份仓库

1.创建hdfs目录 hdfs dfs -mkdir elasticsearch     给目录拥有es用户的权限

2.到es执行

curl -XPUT 'http://ip-es:9200/_snapshot/备份仓库名称' -H 'content-Type:application/json' -d '
{
"type": "hdfs",
"settings": {
"uri": "hdfs://master:8020",
"path": "/elasticsearch/respositories/es_hdfs_repository",
"max_snapshot_bytes_per_sec": "50mb",
"max_restore_bytes_per_sec": "50mb"
}}'

max_snapshot_bytes_per_sec:20mb/s
指定数据从es写入仓库的时候进行限流,默认值20mb/s

max_restore_bytes_per_sec:20mb/s
指定数据从仓库恢复到es的时候进行限流,默认值20mb/s

查询仓库

curl -X GET ip:9200/_snapshot?pretty

注销仓库

curl -X DELETE localhost:9200/_snapshot/仓库名称?pretty

对索引做备份

默认备份所有索引

curl -XPUT 'http://ip:9200/_snapshot/库名/快照名?wait_for_completion=true&pretty' -H 'Content-Type: application/json'

wait_for_completion=true参数表示阻塞该操作,直到该操作执行完成之后在返回。

单独索引快照

curl -XPUT 'http://host:esPort/_snapshot/es_hdfs_repository/snapshot_1?wait_for_completion=true' -d '
{
    "indices":["index1","index2"],
    "ignore_unavailable":true,
    "include_global_state":false,
    "partial":true
}'
# 查看备份进度和结果 curl -XGET 'http://host:esPort/_snapshot/es_hdfs_repository/snapshot_1?pretty'

(1)ignore_unavailable,如果设置为true,则不存在的index会被忽略,不会进行备份。默认情况不设置

(2)include_global_state 设置为false,可以阻止集群把全局的state也作为snapshot一部分备份数据。

删除快照

curl -XDELETE 'http://ip:9200/_snapshot/仓库名/快照名'

数据恢复

索引快照的还原,可以分为两种情况,分别是:

  • 在同一个集群还原快照;
  • 在不同的集群还原快照。

参考链接:https://blog.csdn.net/zuodaoyong/article/details/105022910

参考:https://blog.csdn.net/qq_35246620/article/details/88874767

posted @ 2020-09-09 18:18  鱼丸河粉  阅读(882)  评论(0编辑  收藏  举报