背景:公司采购的一套第三方应用,部署在阿里云上,因为第三方有权限登录该服务器,所以不能将该服务器与公司的内网生产服务器进行打通 ,不能直接接入公司内网的已有的日志采集功能中,现在要想办法将该应用的日志采集到公司的日志采集中。
出于安全原因,公司的内网服务器的端口不能向阿里云服务器开放,google查了下文档,可以filebeat可以安装output.http插件,支持http请求的输出,公司的应用可以配置公网的域名,提供http接口给予阿里云上的filebeat进行调用 ,所以初步定的原型如下图。
这里需要将filebeat首先要安装一个插件,然后重新打包才行,因为原生的filebeat是不支持output.http的。filebeat的github地址是
beats % git remote -v
origin https://github.com/elastic/beats (fetch)
origin https://github.com/elastic/beats (push)
将项目下载到本地,切换版本到7.13版本的分支
参考文档 https://github.com/crazygreenpenguin/beats-output-http 进行插件的安装配置,这个项目的beats-output-http是针对filebeat v7以上版本的,虽然公司使用的filebeat版本是5.1.6,但是因为其相应的 https://github.com/raboof/beats-output-http beats-output-http插件配置好以后,使用go打包时,总是不成功。
package main
import (
"os"
//这里配置插件的github地址
_ "github.com/crazygreenpenguin/beats-output-http"
"github.com/elastic/beats/v7/filebeat/cmd"
inputs "github.com/elastic/beats/v7/filebeat/input/default-inputs"
)
// The basic model of execution:
// - input: finds files in paths/globs to harvest, starts harvesters
// - harvester: reads a file, sends events to the spooler
// - spooler: buffers events until ready to flush to the publisher
// - publisher: writes to the network, notifies registrar
// - registrar: records positions of files read
// Finally, input uses the registrar information, on restart, to
// determine where in each file to restart a harvester.
func main() {
if err := cmd.Filebeat(inputs.Init, cmd.FilebeatSettings()).Execute(); err != nil {
os.Exit(1)
}
}
配置好以后,执行go build命令进行打包,这里要注意,因为我打包的filebeat应用是要在CENTOS系统里运行的,所以打包的命令不能直接使用go build,而要使用如下命令指定运行环境。
env GOOS=linux GOARCH=amd64

本文分享了在阿里云服务器上使用Filebeat进行日志采集的实际经验,详细介绍了如何通过自定义HTTP输出插件实现与公司日志系统的对接,并解决了过程中遇到的延迟和重试等问题。
最低0.47元/天 解锁文章
5273

被折叠的 条评论
为什么被折叠?



