flume采集文件到HDFS

采集文件到HDFS

采集需求:**业务系统使用 log4j 生成的日志,日志内容不断增加,需要把追加到日志文件中的数据实时采集到 hdfs **
根据需求,首先定义一下三大要素:

  • 采集源:即source——监控文件内容更新:exec ‘tail -F file’
  • 下沉目标,即sink——HDFS文件系统:hdfs sink
  • source 和sink之间的传递通道——channel,可用file channel也可以用内存channel

配置文件编写:

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

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /root/logs/test.log
a1.sources.r1.channels = c1

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = /flume/tailout/%y-%m-%d/%H-%M/
a1.sinks.k1.hdfs.filePrefix = itcast-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 10
a1.sinks.k1.hdfs.rollSize = 0
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.batchSize = 1
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


  • exec source 可以执行指定的linux command把命令的结果作为数据进行收集
while true; do date >> /root/logs/test.log;done
#使用该脚本模拟文件数据的实时变化过程
posted @ 2022-05-19 11:37  shan_zhayidian  阅读(179)  评论(0编辑  收藏  举报