本篇內(nèi)容主要講解“Elasticsearch集群數(shù)據(jù)備份與恢復(fù)的方法是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Elasticsearch集群數(shù)據(jù)備份與恢復(fù)的方法是什么”吧!
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),蒲城企業(yè)網(wǎng)站建設(shè),蒲城品牌網(wǎng)站建設(shè),網(wǎng)站定制,蒲城網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,蒲城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
Elasticsearch 擁有副本機(jī)制來保障集群的高可用,然而無法解決如下情況的數(shù)據(jù)丟失:
主副本所在機(jī)器存儲全部損壞。
誤刪除索引數(shù)據(jù)。
升級失敗,數(shù)據(jù)無法回滾。
定期對數(shù)據(jù)做備份,按需恢復(fù)可以很好的解決如上問題。
Elasticsearch 提供了 Snapshot 和 Restore API 用于對集群數(shù)據(jù)完成備份與恢復(fù)。
數(shù)據(jù)備份的過程可以簡單理解成將本地?cái)?shù)據(jù)文件同步到遠(yuǎn)程倉庫(repository) 的過程。
支持全量和增量備份。
repository 常見有如下類型: fs / S3 / HDFS / Azure / Google Cloud Storage。
PUT _template/blog-template { "index_patterns": [ "blog-*" ], "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "dynamic_templates": [ { "integers": { "match": "int_*", "mapping": { "type": "integer" } } }, { "strings": { "match_mapping_type": "string", "mapping": { "type": "keyword", "ignore_above": 256 } } } ], "properties": { "title": { "type": "text" } } } } PUT blog-test POST blog-test/_bulk {"index":{}} {"title":"elasticsearch best practice","author_firstname":"tony","author_lastname":"song","tags":"elasticsearch ,logstash","int_age":18,"locale":"zh,en"} {"index":{}} {"title":"elastic stack release V5","author_firstname":"shay","author_lastname":"banon","tags":"elk ,elasticsearch,release","int_age":28,"locale":"zhc,en"} {"index":{}} {"title":"kibana tutorial","author_firstname":"zen","author_lastname":"wei","tags":"","int_age":38,"locale":"zhc,en"} GET blog-test GET blog-test/_search
修改 elasticsearch.yml 配置文件,增加如下配置:
path.repo: ["/home/elastic/backup"]
重啟elasticsearch進(jìn)程,查看創(chuàng)建的repo:
GET _cluster/settings?include_defaults&filter_path=*.path.repo #輸出結(jié)果: { "defaults" : { "path" : { "repo" : [ "/home/elastic/backup" ] } } }
#創(chuàng)建關(guān)聯(lián) repository PUT /_snapshot/my_fs_backup { "type": "fs", "settings": { "location": "/home/elastic/backup/my_fs_backup", "compress": true } }
查看創(chuàng)建的關(guān)聯(lián):
GET _snapshot/my_fs_backup #輸出結(jié)果: { "my_fs_backup" : { "type" : "fs", "settings" : { "compress" : "true", "location" : "/home/elastic/backup/my_fs_backup" } } }
查看在哪個node上創(chuàng)建了關(guān)聯(lián):
POST _snapshot/my_fs_backup/_verify #輸出結(jié)果 { "nodes" : { "pMrJwVGSQcSgeTZdh71QRw" : { "name" : "node1" } } }
indices
:做快照的索引。
wait_for_completion=true
:是否等待完成快照后再響應(yīng),如果為true會等快照完成后才響應(yīng)。(默認(rèn)為false,不等快照完成立即響應(yīng))
ignore_unavailable
: 設(shè)置為true時,當(dāng)創(chuàng)建快照時忽略不存在的索引。
include_global_state
: 設(shè)置為false時,當(dāng)某個索引所有的主分片不是全部的都可用時,可以完成快照。
#創(chuàng)建snapshot_1對blog-test索引做快照 PUT /_snapshot/my_fs_backup/snapshot_1?wait_for_completion=true { "indices": "blog-test", "ignore_unavailable": true, "include_global_state": false }
查看創(chuàng)建的快照:
GET /_snapshot/my_fs_backup/snapshot_* #GET /_snapshot/my_fs_backup/_all 看所有的 #輸出結(jié)果: { "snapshots" : [ { "snapshot" : "snapshot_1", "uuid" : "FEbAt3BiR1SAiBkO7pfoZg", "version_id" : 7020199, "version" : "7.2.1", "indices" : [ "blog-test" ], "include_global_state" : false, "state" : "SUCCESS", "start_time" : "2021-02-06T03:28:40.001Z", "start_time_in_millis" : 1612582120001, "end_time" : "2021-02-06T03:28:40.213Z", "end_time_in_millis" : 1612582120213, "duration_in_millis" : 212, "failures" : [ ], "shards" : { "total" : 3, "failed" : 0, "successful" : 3 } } ] }
查看快照狀態(tài):
GET _snapshot/my_fs_backup/snapshot_1/_status #輸出結(jié)果: { "snapshots" : [ { "snapshot" : "snapshot_1", "repository" : "my_fs_backup", "uuid" : "FEbAt3BiR1SAiBkO7pfoZg", "state" : "SUCCESS", "include_global_state" : false, "shards_stats" : { "initializing" : 0, "started" : 0, "finalizing" : 0, "done" : 3, "failed" : 0, "total" : 3 }, "stats" : { "incremental" : { "file_count" : 12, "size_in_bytes" : 15608 }, "total" : { "file_count" : 12, "size_in_bytes" : 15608 }, "start_time_in_millis" : 1612582120074, "time_in_millis" : 108 }, "indices" : { "blog-test" : { "shards_stats" : { "initializing" : 0, "started" : 0, "finalizing" : 0, "done" : 3, "failed" : 0, "total" : 3 }, "stats" : { "incremental" : { "file_count" : 12, "size_in_bytes" : 15608 }, "total" : { "file_count" : 12, "size_in_bytes" : 15608 }, "start_time_in_millis" : 1612582120074, "time_in_millis" : 108 }, "shards" : { "0" : { "stage" : "DONE", "stats" : { "incremental" : { "file_count" : 4, "size_in_bytes" : 5104 }, "total" : { "file_count" : 4, "size_in_bytes" : 5104 }, "start_time_in_millis" : 1612582120143, "time_in_millis" : 39 } }, "1" : { "stage" : "DONE", "stats" : { "incremental" : { "file_count" : 4, "size_in_bytes" : 5265 }, "total" : { "file_count" : 4, "size_in_bytes" : 5265 }, "start_time_in_millis" : 1612582120074, "time_in_millis" : 25 } }, "2" : { "stage" : "DONE", "stats" : { "incremental" : { "file_count" : 4, "size_in_bytes" : 5239 }, "total" : { "file_count" : 4, "size_in_bytes" : 5239 }, "start_time_in_millis" : 1612582120113, "time_in_millis" : 21 } } } } } } ] }
rename_pattern
: 正則匹配原索引名
rename_replacement
: 將匹配到的字段用于重命名新索引
POST _snapshot/my_fs_backup/snapshot_1/_restore { "indices": "blog-test", "ignore_unavailable": true, "rename_pattern": "(.+)", "rename_replacement": "restored_$1" }
查詢新索引的數(shù)據(jù):
GET restored_blog-test/_search
到此,相信大家對“Elasticsearch集群數(shù)據(jù)備份與恢復(fù)的方法是什么”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!