nginx

创建nginx docker

  1. docker run -d --name nginx -p 80:80 -v $PWD/log/nginx:/var/log/nginx nginx

在当前目录创建 vim ./etc/fluent.conf 配置文件

  1. <source>
  2. @type tail
  3. path /var/log/nginx/access.log
  4. pos_file /tmp/nginx.access.pos
  5. tag nginx.access.log
  6. <parse>
  7. @type nginx
  8. </parse>
  9. </source>
  10. <match nginx.access.log>
  11. @type copy
  12. <store>
  13. @type stdout
  14. </store>
  15. </match>

启动fluentd

  1. docker run -d --name fluentd -v $(pwd)/etc:/fluentd/etc -v $(pwd)/log:/var/log fluent/fluentd

读取到的信息如下

  1. 2020-08-10 17:39:20.000000000 +0000 nginx.access.log: {"remote":"172.17.0.1","host":"-","user":"-","method":"GET","path":"/","code":"200","size":"612","referer":"-","agent":"curl/7.54.0","http_x_forwarded_for":"-"}

参考

https://docs.fluentd.org/parser