前言
由於之前elasticsearch出現崩潰,導致索引被刪除,只能恢復三天內的數據,因此需要創建快照進行備份,目標至少快速恢復一個月內的數據。
配置過程中原先的7.3版本的repository-s3插件默認使用path-style的方式訪問oss,查看阿里雲OSS幫助文檔告知用戶S3的插件默認使用path-style,而阿里雲僅支持virtual hosted,具體如下:
由於舊版的插件原因,導致無法正常備份快照到阿里雲的oss,從7.4版本開始AWS提供了一個參數,默認使用virtual hosted方式,故升級到7.7版本。
插件配置
安裝repository-s3
bin/elasticsearch-plugin install repository-s3
安裝成功後提示repository-s3 installed,插件安裝完成後需要重啓elasticsearch,才能加載。
到阿里雲後臺生成AccessKey和SecretKey,執行如下命令,將key添加到elasticsearch.keystore
bin/elasticsearch-keystore add s3.client.default.access_key
bin/elasticsearch-keystore add s3.client.default.secret_key
若沒有安裝插件,執行添加key會報命令不存在,key添加完成後需要再次重啓elasticsearch,才能生效。
快照執行步驟
(1)創建快照倉庫
curl -XPUT 'http://10.10.10.1:9200/_snapshot/elk_backup' -H 'Content-Type: application/json' -d '{"type":"s3", "settings":{"bucket":"elkdata","endpoint":"oss-cn-hangzhou-internal.aliyuncs.com","compress":true,"disable_chunked_encoding":true,"base_path":"elkdata","max_snapshot_bytes_per_sec":"500mb","max_restore_bytes_per_sec":"500mb"}}'
參數說明:
type:指定快照倉庫類型爲S3,也就是oss
bucket:指定oss的bucket名稱(阿里雲上查看)
endpoint:指定oss訪問域名(阿里雲上查看)
compress:是否壓縮(默認開啓壓縮,只壓縮元數據文件,索引數據文件不壓縮)
disable_chunked_encoding:是否禁用HTTP服務器響應的分塊編碼
base_path:指定bucket內的存放目錄
max_snapshot_bytes_per_sec:在倉庫單個節點上創建快照的最大速率(默認40mb)
max_restore_bytes_per_sec:在倉庫單個節點上還原快照的最大速率(默認40mb)
(2)創建快照
curl -XPUT 'http://10.10.10.1:9200/_snapshot/elk_backup/elkdata?wait_for_completion=true' -H 'Content-Type: application/json' -d '{"indices":"test-20200529","ignore_unavailable":true,"include_global_state":false}'
參數說明:
wait_for_completion:是否等待快照完成後返回
indices:指定要創建快照的索引,如有多個索引使用英文逗號隔開(如index1,index2)
ignore_unavailable:忽略不存在的索引
include_global_state:防止集羣全局狀態被被存儲爲快照
(3)快照恢復
curl -XPOST 'http://10.10.10.1:9200/_snapshot/elk_backup/elkdata/_restore' -H 'Content-Type: application/json' -d '{"indices":"test-20200529"}'
(4)查看快照狀態
查看倉庫列表
curl -XGET 'http://10.10.10.1:9200/_snapshot/_all?pretty=true'
查看指定倉庫下的所有快照狀態
curl -XGET 'http://10.10.10.1:9200/_snapshot/elk_backup/_all?pretty=true'
查看指定倉庫下指定快照狀態
curl -XGET 'http://10.10.10.1:9200/_snapshot/elk_backup/elkdata/_all?pretty=true'
查看指定倉庫下快照執行狀態
curl -XGET 'http://10.10.10.1:9200/_snapshot/elk_backup/_status?pretty=true'