实践一:监听业务应用日志,收集并输出
实践一:监听业务应用日志,收集并输出
目标:收集容器内的nginx应用的access.log日志,原始日志的格式为:
$ tail -f access.log
...
53.49.146.149 1561620585.973 0.005 502 [27/Jun/2019:15:29:45 +0800] 178.73.215.171 33337 GET https
思路:
-
配置fluent.conf
- 使用@tail插件通过监听access.log文件
- 启动fluentd服务
-
手动追加内容至access.log文件
-
观察本地输出内容是否符合预期
fluent.conf
<source>
@type tail
path /var/log/nginx/access.log
pos_file /var/log/nginx/nginx_access.posg
tag nginx_access
format none
@log_level trace
</source>
<match nginx_access>
@type stdout
</match>
启动服务,追加文件内容 :
# https://github.com/fluent/fluentd-kubernetes-daemonset
$ docker run -u root --rm -ti --entrypoint='' fluent/fluentd-kubernetes-daemonset:v1-debian-elasticsearch-amd64 bash
/ # fluentd -c fluent.conf
/ # echo '53.49.146.149 1561620585.973 0.005 502 [27/Jun/2019:15:29:45 +0800] 178.73.215.171 33337 GET https' \>\>/var/log/nginx/access.log
# 输出结果:
2022-11-19 03:31:42.956800427 +0000 nginx_access: {"message":"53.49.146.149 1561620585.973 0.005 502 [27/Jun/2019:15:29:45 +0800] 178.73.215.171 33337 GET https"}