flume采集使用tail -F比spooldir更好的分析

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

#exec 指的是命令
# Describe/configure the source
a1.sources.r1.type = exec
#F根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪 
#f根据文件的nodeid即文件描述符进行追踪,当文件改名或被删除,追踪停止 
#所以实际生产一般用用tail -F 
#在实际生产中,假如日志是生产在/logs目录下,log4j的日志文件肯定是会根据规则进行滚动的:当*.log满了就会滚动把前文件更名为*.log.1,然后重新进行*.log文件打印。
#如果采用spooldir来监控/log文件夹,flume会采集.log数据,但是滚动生成.log.1,flume就会把*.log.1文件当作新文件,又重新读取一遍,导致重复。
#所以使用tail -F *.log比较好,当文件达到一定大小后,log4j会把.log改为.log.1,然后新建一个.log继续写 即使.log被改名了,但是之后再次创建相同的文件名,会继续追踪  所以不会重复消费 但是不能用tail -f
#而且采集中断后,tail -F 监控的是.log文件,之前的文件数据已经滚动改名成别的文件了,所以当前.log中的数据不会很大,所以即使发生重复采集(tail -F会读取文件的原始数据并监控新的数据),
#重复的数据也不会很多,重复的是当前.log中生成的数据,最多重复采集的也就是一个.log的阈值大小。

a1.sources.r1.command = tail -F /home/hadoop/testlogs/test.log
a1.sources.r1.channels = c1

# Describe the sink
#下沉目标
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
#指定目录, flume帮做目的替换
a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/
#文件的命名, 前缀
a1.sinks.k1.hdfs.filePrefix = events-

#10 分钟就改目录,生成新的目录 2018-11-20/1010  2018-11-20/1020  2018-11-20/1030
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute

#时间:每3s滚动生成一个新的文件 0表示不使用时间来滚动
a1.sinks.k1.hdfs.rollInterval = 3

#空间: 文件滚动的大小限制(bytes) 当达到500b是滚动生成新的文件
a1.sinks.k1.hdfs.rollSize = 500

#写入多少个event数据后滚动文件(事件个数),滚动生成新的文件
a1.sinks.k1.hdfs.rollCount = 20

#5个事件就开始往里面写入
a1.sinks.k1.hdfs.batchSize = 5

#用本地时间格式化目录
a1.sinks.k1.hdfs.useLocalTimeStamp = true

#下沉后, 生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
a1.sinks.k1.hdfs.fileType = DataStream

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

猜你喜欢

转载自blog.csdn.net/qq_32563713/article/details/81159554