Elasticsearch 是一个开源的分布式 RESTful 搜索和分析引擎。它能够在近实时条件下,存储,查询和分析海量的数据。它还支持将快照备份至HDFS/S3上面,而阿里云OSS兼容S3的API,本文将介绍如何使用ES的Repository-S3插件将快照备份至OSS。html
首先,咱们须要安装repository-s3,能够参考官方文档:
https://www.elastic.co/guide/en/elasticsearch/plugins/7.2/repository-s3.htmlexpress
启动ES,咱们能够从log中看到,ES已经load了这个plugin:json
[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去,分别执行下面的命令:app
bin/elasticsearch-keystore add s3.client.default.access_key bin/elasticsearch-keystore add s3.client.default.secret_key
首先,咱们建立一个备份:less
[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协议来传输数据,若是想使用http协议,须要将"protocol": "http", "disable_chunked_encoding": true
加到settings
里面(这个特性将会在新版本发布后可用)。curl
能够使用下面的命令来确实建立是否成功:elasticsearch
[root@master ~]# curl -XGET localhost:9200/_snapshot/test?pretty { "test" : { "type" : "s3", "settings" : { "bucket" : "hadoop-oss-test", "endpoint" : "oss-cn-zhangjiakou-internal.aliyuncs.com" } } }
咱们能够写入一些测试数据到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索引:ide
[root@master ~]# curl -XPUT 'http://localhost:9200/_snapshot/test/sales' -H 'Content-Type: application/json' -d '{ "indices": "sales" }' {"accepted":true}
而后咱们能够从OSS控制台看到备份的结果:oop
如今咱们再往sales索引里面写一些数据:
[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索引,分别执行下面的命令:
[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索引跟以前的一致。
原文连接 本文为云栖社区原创内容,未经容许不得转载。