05、使用flume采集日志

本文详细介绍如何使用Flume的TAILDIR source进行日志文件采集配置。通过具体配置示例,展示如何设置source、sink、channel及启动Flume agent的过程。适用于希望了解Flume日志采集实践的读者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编写flume配置

使用TAILDIR source

#表示将r1和c1连接起来
# Name the components on this agent  #表示agent的名称
#r1表示a1的输入源
a1.sources = r1
#k1表示a1的输出目的地
a1.sinks = k1
#c1表示a1的缓冲区
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /opt/logs/visitaction.log
#表示将r1和c1连接起来
a1.sources.r1.channels = c1

# Describe the sink
#表示a1的输出目的地是控制台logger类型
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = /flume/visitactionlog/%y-%m/%d
a1.sinks.k1.hdfs.filePrefix = visitaction-
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.fileType=DataStream
# Use a channel which buffers events in memory
#表示a1的channel类型是memory内存型
a1.channels.c1.type = memory
#表示a1的channel总容量是1000个event
a1.channels.c1.capacity = 1000
#表示a1的channel传输时收集到了100条event以后再去提交事务
a1.channels.c1.transactionCapacity = 100

命名为visitaction.conf

启动flume

bin/flume-ng agent --conf conf/ --name a1 --conf-file job/visitaction.conf

启动打印日志程序

nohup java -cp printlog.jar com.zj.mysparkproject.PrintVisitActionLog start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值