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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM