flume的使用:監聽文件夾

1.新建配置文件flumejob_dir.conf

# 定義別名
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = spooldir
# 監控的文件夾
a1.sources.r1.spoolDir = /opt/testdir
# 上傳成功後顯示後綴名 
a1.sources.r1.fileSuffix = .COMPLETED
# 如論如何 加絕對路徑的文件名 默認false
a1.sources.r1.fileHeader = true
#忽略所有以.tmp 結尾的文件(正在被寫入),不上傳
# ^以任何開頭 出現無限次 以.tmp結尾的
a1.sources.r1.ignorePattern = ([^ ]*\.tmp)

# Describe the sink 下沉到hdfs
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://hadoop2:9000/flume/testdir/%Y%m%d/%H
#上傳文件的前綴
a1.sinks.k1.hdfs.filePrefix = testdir-
#是否按照時間滾動文件夾
a1.sinks.k1.hdfs.round = true
#多少時間單位創建一個新的文件夾
a1.sinks.k1.hdfs.roundValue = 1
#重新定義時間單位
a1.sinks.k1.hdfs.roundUnit = hour
#是否使用本地時間戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#積攢多少個 Event 才 flush 到 HDFS 一次
a1.sinks.k1.hdfs.batchSize = 100
#設置文件類型,可支持壓縮
a1.sinks.k1.hdfs.fileType = DataStream
#多久生成一個新的文件
a1.sinks.k1.hdfs.rollInterval = 600
#設置每個文件的滾動大小大概是 128M 
a1.sinks.k1.hdfs.rollSize = 134217700
#文件的滾動與 Event 數量無關
a1.sinks.k1.hdfs.rollCount = 0
#最小副本數
a1.sinks.k1.hdfs.minBlockReplicas = 1

# 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

2.啓動

cd /opt/module/flume  
 
bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/flumejob_dir.conf

3.在文件夾內進行操作,比如新建文件,修改文件,之後文件會有後綴名.COMPLETED

  • 注意:所監控的文件夾內不允許有子文件夾

image.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章