网站首页 > 技术文章 正文
前言
Elasticsearch 是一个开源的分布式 RESTful 搜索和分析引擎。它可以在近实时条件下,存储,查询和分析海量的数据。它还支持将快照备份至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已经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去,分别执行下面的命令:
bin/elasticsearch-keystore add s3.client.default.access_key bin/elasticsearch-keystore add s3.client.default.secret_key
运行
首先,我们创建一个备份:
[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里面(这个特性将会在新版本发布后可用)。
可以使用下面的命令来确实创建是否成功:
[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索引:
[root@master ~]# curl -XPUT 'http://localhost:9200/_snapshot/test/sales' -H 'Content-Type: application/json' -d '{ "indices": "sales" }'
{"accepted":true}
然后我们可以从OSS控制台看到备份的结果:
现在我们再往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索引跟之前的一致。
参考资料
https://www.elastic.co/guide/en/elasticsearch/plugins/7.2/repository-s3.html
https://www.elastic.co/cn/products/elasticsearch
作者:冷月_wjh
猜你喜欢
- 2024-10-23 微软发布6月Win11累积更新KB5039212/KB5039213
- 2024-10-23 快速体验之《gor+diffy实现线上流量复制到测试环境》
- 2024-10-23 Colbie Caillat: Try(colbiecaillattry歌词)
- 2024-10-23 基于阿里云 ASK 的 Istio 微服务应用部署初探
- 2024-10-23 浅谈ElasticSearch 集群部署(elastic集群配置)
- 2024-10-23 Python项目中跟踪系统导入Zipkin(基于python的目标跟踪算法)
- 2024-10-23 JVM参数及调优(jvm调优常用参数)
- 2024-10-23 Elasticsearch的路由routing的应用技巧
- 2024-10-23 利用工具curl来查看http请求和https请求
- 2024-10-23 一些超实用的 Kubernetes 日常运维常用命令,建议收藏
- 最近发表
-
- 聊一下 gRPC 的 C++ 异步编程_grpc 异步流模式
- [原创首发]安全日志管理中心实战(3)——开源NIDS之suricata部署
- 超详细手把手搭建在ubuntu系统的FFmpeg环境
- Nginx运维之路(Docker多段构建新版本并增加第三方模
- 92.1K小星星,一款开源免费的远程桌面,让你告别付费远程控制!
- Go 人脸识别教程_piwigo人脸识别
- 安卓手机安装Termux——搭建移动服务器
- ubuntu 安装开发环境(c/c++ 15)_ubuntu安装c++编译器
- Rust开发环境搭建指南:从安装到镜像配置的零坑实践
- Windows系统安装VirtualBox构造本地Linux开发环境
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (77)
- vector线程安全吗 (73)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)
