为了账号安全,请及时绑定邮箱和手机立即绑定

从对象存储服务同步数据到Elasticsearch

标签:
人工智能

AWS的S3, 阿里云的OSS, 腾讯云的COS, 都是常见的对象存储服务。对象存储服务面向非结构化数据,支持通过HTTP/HTTPS协议访问,支持存入文本、图片、视频等多种类型的数据。

实际应用中,部分云计算产品会把业务日志存进对象存储中,如腾讯云容器服务的容器运行日志,腾讯云负载均衡服务的实例访问日志等。日志虽然存进相对廉价的对象存储bucket中了,但是查看或检索起来比较麻烦,还是把日志存进Elasticsearch,通过Kibana进行检索比较靠谱。

本文利用之前自行开发的logstash-input-cos插件,将存放在腾讯云对象存储服务COS中的日志,通过logstash同步到Elasticsearch中,以实现日志的快速查看与检索。

logstash-input-cos插件

logstash-input-cos插件的github地址:https://github.com/gaobinlong/logstash-input-cos.git

安装logstash-input-cos插件

拉取logstash-input-cos插件:

git clone https://github.com/gaobinlong/logstash-input-cos.git

进入logstash的解压目录,执行:

./bin/logstash-plugin install ~/logstash-input-cos/logstash-input-cos-0.0.1-java.gem

执行结果为:

Validating /usr/local/githome/logstash-input-cos/logstash-input-cos-0.0.1-java.gem
Installing logstash-input-cosInstallation successful

编写配置文件

编写配置文件cos.logstash.conf

input {
    cos {        "endpoint" => "cos.ap-guangzhou.myqcloud.com" # COS访问域名
        "access_key_id" => "*****" # 腾讯云账号secret id
        "access_key_secret" => "****" # 腾讯云账号secret key
        "bucket" => "******" # 腾讯云COS bucket
        "region" => "ap-guangzhou" # 腾讯云COS bucket所在地域
        "appId" => "**********" # 腾讯云账号appId
        "interval" => 60 # 数据同步时间间隔,每60s拉取一次数据
    }
}

output {
    elasticsearch {
    hosts => ["http://172.16.0.39:9200"] # ES endpoint地址
    index => "access.log" # 索引
 }
}

执行logstash

./bin/logstash -f cos.logstash.conf

通过kibana查看日志

通过kibana查看从COS中同步到ES中的日志:


700

image



作者:bellengao
链接:https://www.jianshu.com/p/160be1f15e5e


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消