通过一个例子进行阶段总结。

本示例使用到如下插件:in_tail, out_copy, out_stdout, out_forward, in_forward。

本示例包含两个节点:

node_forwarder:

使用in_tail收集nginx的access日志,将其输出到stdout,同时通过out_forward转发给节点node_aggregator。

node_aggregator:

使用in_forward接收节点node_forwarder转发的日志,将其输出到stdout。

这种部署方式采用的是官方建议的高可用架构。

这两个节点位于同一服务器上,我们通过给td-agent指定不同的启动参数,来启动两个节点。

  1. 部署过程

    首先,在服务器上部署nginx,并开启一个简单的http服务器。

    nginx日志格式取默认值。

    nginx日志文件路径为:/usr/local/openresty/nginx/logs/access.log

然后,在服务器上配置node_forwarder。

配置文件/etc/td-agent/node_forwarder.conf内容如下:

<source>
@type tail
path /usr/local/openresty/nginx/logs/access.log
pos_file /tmp/td-node_forwarder.pos
tag td.nginx.access
<parse>
@type nginx
</parse>
</source> <match td.nginx.*>
@type copy
<store>
@type stdout
</store>
<store>
@type forward
<server>
host 127.0.0.1
port 24224
</server>
<secondary>
@type file
path /tmp/td-node_forwarder-failed.log
</secondary>
</store>
</match>

启动node_forwarder:

td-agent -c /etc/td-agent/node_forwarder.conf --daemon /var/run/td-agent/node_forwarder.pid -o /tmp/td-node_forwarder.log

参数说明:

  • -c:指定td-agent使用的配置文件
  • --daemon:指定pid文件
  • -o:指定运行日志文件路径

最后,在服务器上配置node_aggregator。

配置文件/etc/td-agent/node_aggregator.conf内容如下:

<source>
@type forward
</source> <match td.nginx.*>
@type stdout
</match>

启动node_aggregator:

td-agent -c /etc/td-agent/node_aggregator.conf --daemon /var/run/td-agent/node_aggregator.pid -o /tmp/td-node_aggregator.log
  1. 测试过程

    接下来,我们使用curl访问nginx:
curl http://127.0.0.1:8090/

得到如下日志:

127.0.0.1 - - [23/May/2020:18:43:09 +0800] "GET / HTTP/1.1" 200 558 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"

然后分别查看这两个Fluentd节点的运行日志。

node_forwarder日志输出如下:

2020-05-23 18:43:09.000000000 +0800 td.nginx.access: {"remote":"127.0.0.1","host":"-","user":"-","method":"GET","path":"/","code":"200","size":"558","referer":"-","agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"}

node_aggregator日志输出如下:

2020-05-23 18:43:09.000000000 +0800 td.nginx.access: {"remote":"127.0.0.1","host":"-","user":"-","method":"GET","path":"/","code":"200","size":"558","referer":"-","agent":"curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"}

可以看到对nginx的访问被正确记录到了这两个节点中。

  1. 结语

    通过本次测试示例,我们演示了in_tail、out_copy、out_stdout、out_forward 和 in_forward这几个插件的基本用法。同时也使用到了parser插件用来解析nginx的默认日志。

    这里通过组合out_copy和out_stdout给大家提供了一种调试Fluentd配置的思路,即:在将日志发送到目的端的同时,将其写入本地标准输出(或运行日志),以观察当前节点是否正确处理了日志,从而缩小排查疑难的范围。

最新文章

  1. Life cycle of plist in Lockdown changes dramatically in iOS 10
  2. [转]使用EasyRsa3为OpenVPN生成密码
  3. Hinet 日本数据处理流程
  4. flask中&#39;bool&#39; object has no attribute &#39;__call__&#39;问题
  5. 让input不可编辑的方法
  6. linux 标准 GPIO 操作
  7. Developing iOS8 Apps with Swift——iOS8概览
  8. Solr配置集群
  9. CentOS 6.5 + Nginx 1.8.0 + PHP 5.6(with PHP-FPM) 负载均衡源码安装 之 (三)Nginx负载均衡配置
  10. 通过pull解析器操作安卓的xml
  11. Android 如何引用com.android.internal.R目录下的资源
  12. C语言生成2000w行数据
  13. UML在需求分析与系统设计中之实战讲解
  14. shell编程之sed
  15. 用java实现简单快速的webservice客户端/数据采集器(支持soap1.1和soap1.2标准,支持utf-8编码)
  16. salesforce lightning零基础学习(一) lightning简单介绍以及org开启lightning
  17. Axios源码深度剖析 - 替代$.ajax,成为xhr的新霸主
  18. 【Jenkins】新版本的特性:自定义流水线
  19. 【转】java:Session(会话)机制详解
  20. 机器学习性能度量指标:AUC

热门文章

  1. vue3代码编写
  2. 4-2 Spring MVC框架-01
  3. 第七天python3 函数、参数及参数解构(二)
  4. 第五天python3 内建函数总结
  5. 智慧文旅IOC大数据可视化建设方案
  6. 十分钟教会你如何使用VitePress搭建及部署个人博客站点
  7. UnifyRemoteManager-多国语言绿色版v1.3-20200315,统一远程连接自动登录软件,欢迎测试
  8. DolphinScheduler 集群高可用测试:有效分摊服务器压力,达到性能最大优化!
  9. Git 使用技巧(一):合并分支
  10. 【HMS core】【FAQ】典型问题合集7