如何将Elasticsearch的快照备份至OSS
前言
Elasticsearch 是一個開源的分布式 RESTful 搜索和分析引擎。它可以在近實時條件下,存儲,查詢和分析海量的數(shù)據(jù)。它還支持將快照備份至HDFS/S3上面,而阿里云OSS兼容S3的API,本文將介紹如何使用ES的Repository-S3插件將快照備份至OSS。
部署與配置
首先,我們需要安裝repository-s3,可以參考官方文檔:
https://www.elastic.co/guide/en/elasticsearch/plugins/7.2/repository-s3.html
啟動ES,我們可以從log中看到,ES已經(jīng)load了這個plugin:
[2019-07-15T14:12:09,225][INFO ][o.e.p.PluginsService ] [master] loaded module [aggs-matrix-stats] [2019-07-15T14:12:09,225][INFO ][o.e.p.PluginsService ] [master] loaded module [analysis-common] [2019-07-15T14:12:09,225][INFO ][o.e.p.PluginsService ] [master] loaded module [ingest-common] [2019-07-15T14:12:09,226][INFO ][o.e.p.PluginsService ] [master] loaded module [ingest-geoip] [2019-07-15T14:12:09,226][INFO ][o.e.p.PluginsService ] [master] loaded module [ingest-user-agent] [2019-07-15T14:12:09,226][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-expression] [2019-07-15T14:12:09,226][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-mustache] [2019-07-15T14:12:09,227][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-painless] [2019-07-15T14:12:09,227][INFO ][o.e.p.PluginsService ] [master] loaded module [mapper-extras] [2019-07-15T14:12:09,227][INFO ][o.e.p.PluginsService ] [master] loaded module [parent-join] [2019-07-15T14:12:09,227][INFO ][o.e.p.PluginsService ] [master] loaded module [percolator] [2019-07-15T14:12:09,227][INFO ][o.e.p.PluginsService ] [master] loaded module [rank-eval] [2019-07-15T14:12:09,228][INFO ][o.e.p.PluginsService ] [master] loaded module [reindex] [2019-07-15T14:12:09,228][INFO ][o.e.p.PluginsService ] [master] loaded module [repository-url] [2019-07-15T14:12:09,228][INFO ][o.e.p.PluginsService ] [master] loaded module [transport-netty4] [2019-07-15T14:12:09,228][INFO ][o.e.p.PluginsService ] [master] loaded plugin [repository-s3] [2019-07-15T14:12:12,375][INFO ][o.e.d.DiscoveryModule ] [master] using discovery type [zen] and seed hosts providers [settings] [2019-07-15T14:12:12,801][INFO ][o.e.n.Node ] [master] initialized [2019-07-15T14:12:12,802][INFO ][o.e.n.Node ] [master] starting ...然后,我們需要將OSS使用的Access Key和Secret Key配置到ES去,分別執(zhí)行下面的命令:
bin/elasticsearch-keystore add s3.client.default.access_key bin/elasticsearch-keystore add s3.client.default.secret_key運行
首先,我們創(chuàng)建一個備份:
[root@master ~]# curl -XPUT 'http://localhost:9200/_snapshot/test' -H 'Content-Type: application/json' -d '{ "type": "s3", "settings": { "bucket": "hadoop-oss-test", "endpoint": "oss-cn-zhangjiakou-internal.aliyuncs.com"} }' {"acknowledged":true}NOTE:?上面的命令默認使用https協(xié)議來傳輸數(shù)據(jù),如果想使用http協(xié)議,需要將"protocol": "http", "disable_chunked_encoding": true加到settings里面(這個特性將會在新版本發(fā)布后可用)。
可以使用下面的命令來確實創(chuàng)建是否成功:
[root@master ~]# curl -XGET localhost:9200/_snapshot/test?pretty {"test" : {"type" : "s3","settings" : {"bucket" : "hadoop-oss-test","endpoint" : "oss-cn-zhangjiakou-internal.aliyuncs.com"}} }我們可以寫入一些測試數(shù)據(jù)到ES,然后看下目前集群的索引信息:
[root@master ~]# curl -X GET "localhost:9200/_cat/indices?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open sales 89ouBy6RQsuT34QRbn_jeQ 10 0 271786 0 15mb 15mb green open customer fQCMEvXsQOu0UgMm1SAJlA 5 0 10000 0 717kb 717kb假設我們只備份sales索引:
[root@master ~]# curl -XPUT 'http://localhost:9200/_snapshot/test/sales' -H 'Content-Type: application/json' -d '{ "indices": "sales" }' {"accepted":true}然后我們可以從OSS控制臺看到備份的結果:
現(xiàn)在我們再往sales索引里面寫一些數(shù)據(jù):
[root@master ~]# curl -X GET "localhost:9200/_cat/indices?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open sales 89ouBy6RQsuT34QRbn_jeQ 10 0 281502 0 15.6mb 15.6mb green open customer fQCMEvXsQOu0UgMm1SAJlA 5 0 10000 0 717kb 717kb我們利用剛才備份到OSS的快照來恢復sales索引,分別執(zhí)行下面的命令:
[root@master ~]# curl -XPOST localhost:9200/sales/_close {"acknowledged":true,"shards_acknowledged":true,"indices":{"sales":{"closed":true}}} [root@master ~]# curl -XPOST 'http://localhost:9200/_snapshot/test/sales/_restore?pretty' {"accepted" : true } [root@master ~]# curl -X GET "localhost:9200/_cat/indices?v" health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open sales 89ouBy6RQsuT34QRbn_jeQ 10 0 271786 0 15mb 15mb green open customer fQCMEvXsQOu0UgMm1SAJlA 5 0 10000 0 717kb 717kb我們可以看到,sales索引跟之前的一致。
原文鏈接
本文為云棲社區(qū)原創(chuàng)內容,未經(jīng)允許不得轉載。
總結
以上是生活随笔為你收集整理的如何将Elasticsearch的快照备份至OSS的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL8.0 - 新特性 - 说说I
- 下一篇: 36氪联合阿里云,共同研制中小企业发展「