我想直接从Apache发送到Fluentd!

这是一个基于备忘录的系统。

由于从 Apache 中跟踪日志文件并考虑轮换等问题非常麻烦,所以我尝试了各种试验和错误。

请提前进行必要的设置。

    • apache

 

    • fluentd

 

    selinuxとかセキュリティ周り

将Apache LogFormat转换为类似这样的JSON格式。


LogFormat "{\"remotehost\":\"%h\",\"ident\":\"%l\",\"user\":\"%u\",\"datetime\":\"%t\",\"request\":\"%r\",\"status\":\"%>s\",\"byte\":\"%b\",\"referer\":\"%{Referer}i\",\"user_agent\":\"%{User-Agent}i\",\"time_taken\":%D}" combinedjson

CustomLog "|/opt/td-agent/bin/fluent-cat -p 24224 test" combinedjson

Fluentd的一侧可以这样随机选择。

<source>
  type forward
  port 24224
  bind 0.0.0.0
  tag test
  <parse>
    type json
  </parse>
</source>

<match test>
  type stdout
</match>

这样做,它开始动了。

2022-04-04 16:36:26.937969132 +0900 test: {"remotehost":"192.168.56.1","ident":"-","user":"-","datetime":"[04/Apr/2022:16:36:26 +0900]","request":"GET /index.html HTTP/1.1","status":"304","byte":"-","referer":"-","user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36","time_taken":179}

后面随便修改就可以了…这样就不用烦恼文件管理了。虽然考虑过将结果输出到stdout,但是觉得分离错误和其他日志会比较麻烦,所以觉得分别使用端口或套接字更方便使用。

广告
将在 10 秒后关闭
bannerAds