1. 程式人生 > 其它 >flume採集檔案到HDFS

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
#使用該指令碼模擬檔案資料的實時變化過程