1.安装yum install td-agent
2.启动systemctl start td-agent
3.修改配置 /etc/td-agent/td-agent.conf
增加配置(例子:文件发到kafka)
<source>
@type tail
path /data0/log/nginx/*.log
pos_file /var/log/td-agent/xxtopic.pos
tag nginx-access-tracking
format none
</source>
<match nginx-access-tracking>
@type kafka_buffered
brokers localhost:9092
buffer_type file
buffer_path /var/log/td-agent/buffer
flush_interval 5s
output_data_type json
</match>
4.额外:修改启动用户为root ,避免发生目录权限问题
/etc/init.d/td-agent
注意:
1初次启动的时候历史文件最好清空
2flentd宕机期间文件的变化在启动后会继续传输
3tag 和 match需要匹配
踩坑
logstash/tdagent的kafka推送都会包一层message在外面, 做api的时候往往就忽略导致数据格式不一致,功能出现问题不易定位,需要做到输入输出一致。
- output_data_type json //带message包含
- output_data_type attr: message //不带message