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 ...
随机推荐
- Reading configuration from: /usr/local/src/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
2021-04-25 00:15:48,112 [myid:] - INFO [main:QuorumPeerConfig@174] - Reading configuration from: /u ...
- 一个豆瓣电影Top250爬虫
一个爬虫 这是我第一次接触爬虫,写的第一个爬虫实例. https://movie.douban.com/top250 模块 import requests #用于发送请求 import re #使用正 ...
- 4-11 Spring Security及SSO
1. 关于用户身份认证与授权 Spring Security是用于解决认证与授权的框架. 在根项目下创建新的csmall-passport子模块,最基础的依赖项包括spring-boot-starte ...
- 五分钟给你的 gRPC服务 加上 HTTP 接口
gRPC 服务要加 HTTP 接口? go-zero 给大家带来极简的 RESTful 和 gRPC 服务开发体验的同时,社区又给我们提出了新的期望: 我想只写一次代码 既要 gRPC 接口 也要 H ...
- 重写Object的equals方法和Objects的equals方法
Object类的equals方法默认比较的是两个对象的地址值,没有意义 所以我们需要重写equals方法,比较两个对象的属性值(name,age等等): 对象的属性值一样返回true否则返回false ...
- vscode problem
1.Inconsistent use of tabs and spaces in indentation 原因:tab和空格键不能同时使用 vs code按住ctrl + p,输入以下内容 >c ...
- ExcelPatternTool: Excel表格-数据库互导工具
ExcelPatternTool Excel表格-数据库互导工具 介绍: 指定Pattern文件-一个规则描述的json文档,基于此规则实现Excel表格与数据库之间的导入导出,校验等功能. 特点: ...
- 日夕如是寒暑不间,基于Python3+Tornado6+APScheduler/Celery打造并发异步动态定时任务轮询服务
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_220 定时任务的典型落地场景在各行业中都很普遍,比如支付系统中,支付过程中因为网络或者其他因素导致出现掉单.卡单的情况,账单变成了 ...
- 协程 && 异步例子
# 异步redis # 在使用python代码操作redis的时候,连接.操作.断开都是网络IO. # 安装aioredis模块: pip install aioredis==1.3.1 # 例: 该 ...
- ZOJ 3537 (凸包 + 区间DP)(UNFINISHED)
#include "Head.cpp" const int N = 10007; int n, m; struct Point{ int x,y; bool operator &l ...