16. 综合使用tail、forward、copy和stdout
通过一个例子进行阶段总结。
本示例使用到如下插件: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指定不同的启动参数,来启动两个节点。
- 部署过程
首先,在服务器上部署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
- 测试过程
接下来,我们使用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的访问被正确记录到了这两个节点中。
- 结语
通过本次测试示例,我们演示了in_tail、out_copy、out_stdout、out_forward 和 in_forward这几个插件的基本用法。同时也使用到了parser插件用来解析nginx的默认日志。
这里通过组合out_copy和out_stdout给大家提供了一种调试Fluentd配置的思路,即:在将日志发送到目的端的同时,将其写入本地标准输出(或运行日志),以观察当前节点是否正确处理了日志,从而缩小排查疑难的范围。
16. 综合使用tail、forward、copy和stdout的更多相关文章
- 每天一个linux命令(16):tail命令
版权声明更新:2017-05-20博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下面的mv命令. 2. ...
- COPY - 在表和文件之间拷贝数据
SYNOPSIS COPY tablename [ ( column [, ...] ) ] FROM { 'filename' | STDIN } [ [ WITH ] [ BINARY ] [ O ...
- ubuntu 16.04源码编译和配置caffe详细教程 | Install and Configure Caffe on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/b90033a9/,欢迎阅读! Install and Configure Caffe on ubuntu 16.04 Series ...
- postgresql学习笔记--基础篇 - copy
1. psql 导入/导出数据 psql支持文件数据导入到数据库,也支持数据库表数据导出到文件中. COPY命令和\copy 命令都支持这两类操作,但两者有如下区别: COPY 命令是SQL命令,\c ...
- Ubuntu 16.04上搭建CDH5.16.1集群
本文参考自:<Ubuntu16.04上搭建CDH5.14集群> 1.准备三台(CDH默认配置为三台)安装Ubuntu 16.04.4 LTS系统的服务器,假设ip地址分布为 192.168 ...
- [C++ Primer] : 第16章: 模板与泛型编程
面向对象编程(OOP)和泛型编程都能处理在编写程序时不知道类型的情况, 不同之处在于: OOP能处理类型在程序运行之前都未知的情况, 而在泛型编程中, 在编译时就能获知类型了. 函数模板 模板是C++ ...
- Postgres copy命令导入导出数据
最近有需要对数据进行迁移的需求,由于postgres性能的关系,单表3000W的数据量查询起来有一些慢,需要对大表进行切割,拆成若干个子表,涉及到原有数据要迁移到子表的需求.起初的想法是使用存储过程, ...
- Busybox的syslogd认识与使用
关键词:rcS.start-stop-daemon.syslogd.syslog().klogd.klogctl().syslog.conf./dev/log.facility/level等等. sy ...
- The Go Programming Language. Notes.
Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...
随机推荐
- day05 Java网络编程socket 与多线程
java网络编程 java.net.Socket Socket(套接字)封装了TCP协议的通讯细节,是的我们使用它可以与服务端建立网络链接,并通过 它获取两个流(一个输入一个输出),然后使用这两个流的 ...
- oracle删除超过N天数据脚本
公司内做的项目是工厂内的,一般工厂内数据要求的是实时性,很久之前的数据可以自行删除处理,我们数据库用的oracle,所以就想着写一个脚本来删除,这样的话,脚本不管放在那里使用都可以达到效果 由于服务器 ...
- 【web自动化测试】playwright安装失败怎么办
在安装中,如果没有输入 playwright install, 则不会安装浏览器,运行 playwright codegen 时会报浏览器找不到的错误: "chromium" br ...
- Camera类定义和实现
类声明: #pragma once #ifndef __CAMERA_HEADER__ #define __CAMERA_HEADER__ #include "../utilities/ge ...
- 【安全通告】关于 DolphinScheduler 漏洞情况的说明
点击上方 蓝字关注我们 [安全通报] [影响程度:低] Apache DolphinScheduler 社区邮件列表最近通告了 1 个漏洞,考虑到有很多用户并未订阅此邮件列表,我们特地在此进行情况说明 ...
- 皮皮调度(1)——从Airflow到DolphinScheduler,以及“皮皮调度”的来历
按照前一篇文章 <GraalVM -- 让Java变得再次强大> 末尾提到的计划,本来这篇文章是想写一下GraalVM的后续<深耕云原生的Java应用框架 -- Quarkus> ...
- 清晰梳理最全日志框架关系与日志配置-SpringBoot 2.7.2 实战基础
优雅哥 SpringBoot 2.7.2 实战基础 - 07 - 日志配置 Java 中日志相关的 jar 包非常多,log4j.log4j2.commons-logging.logback.slf4 ...
- React报错之Expected an assignment or function call and instead saw an expression
正文从这开始~ 总览 当我们忘记从函数中返回值时,会产生"Expected an assignment or function call and instead saw an express ...
- Vue3 发生错误:setup function returned a promise
当你组件中有 Promise 对象时,即 Axios.Ajax 这类的请求,然后把数据渲染到模板中就会报如下图的错误: 在这个异步组件外包裹一个 <Suspense> 组件.比如 App. ...
- linux --stdin 管道 标准输入重定向
linux --stdin 标准输入重定向 --stdin This option is used to indicate that passwd should read the new passwo ...