需求
配置conf
vim dir-hdfs-tail.conf
# Name the components on this agent
a4.sources = r4
a4.sinks = k4
a4.channels = c4
# Describe/configure the source
a4.sources.r4.type = TAILDIR
a4.sources.r4.positionFile = /flume-tail/tail_dir.json
a4.sources.r4.filegroups = f1 f2
a4.sources.r4.filegroups.f1 = /flume-tail/files/.*file.*
a4.sources.r4.filegroups.f2 = /flume-tail/files2/.*log.*
# Describe the sink
a4.sinks.k4.type = hdfs
a4.sinks.k4.hdfs.path = hdfs://hadoop100:9000/flume/dir-tail/%Y%m%d/%H
#上传文件的前缀
a4.sinks.k4.hdfs.filePrefix = dir-tail-
#是否按照时间滚动文件夹
a4.sinks.k4.hdfs.round = true
#多少时间单位创建一个新的文件夹
a4.sinks.k4.hdfs.roundValue = 1
#重新定义时间单位
a4.sinks.k4.hdfs.roundUnit = hour
#是否使用本地时间戳
a4.sinks.k4.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a4.sinks.k4.hdfs.batchSize = 100
#设置文件类型,可支持压缩
a4.sinks.k4.hdfs.fileType = DataStream
#多久生成一个新的文件
a4.sinks.k4.hdfs.rollInterval = 20
#设置每个文件的滚动大小
a4.sinks.k4.hdfs.rollSize = 134217700
#文件的滚动与 Event 数量无关
a4.sinks.k4.hdfs.rollCount = 0
# Use a channel which buffers events in memory
a4.channels.c4.type = memory
a4.channels.c4.capacity = 1000
a4.channels.c4.transactionCapacity = 100
# Bind the source and sink to the channel
a4.sources.r4.channels = c4
a4.sinks.k4.channel = c4
启动
bin/flume-ng agent --name a4 --conf-file job/dir-hdfs-tail.conf -Dflume.foot.logger=INFO,console