Flume實戰採集文件內容存入HDFS

1、flume安裝目錄下新建文件夾 example 

2、在example下新建文件 

log-hdfs.conf

內容如下:

[plain] view plain copy
  1. # Name the components on this agent  
  2. a1.sources = r1  
  3. a1.sinks = k1  
  4. a1.channels = c1  
  5.   
  6. #exec 指的是命令  
  7. # Describe/configure the source  
  8. a1.sources.r1.type = exec  
  9. #F根據文件名追中, f根據文件的nodeid追中  
  10. a1.sources.r1.command = tail -F /home/hadoop/testdata/testflume.log  
  11. a1.sources.r1.channels = c1  
  12.   
  13. # Describe the sink  
  14. #下沉目標  
  15. a1.sinks.k1.type = hdfs  
  16. a1.sinks.k1.channel = c1  
  17. #指定目錄, flum幫做目的替換  
  18. a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/  
  19. #文件的命名, 前綴  
  20. a1.sinks.k1.hdfs.filePrefix = events-  
  21.   
  22. #10 分鐘就改目錄(創建目錄), (這些參數影響/flume/events/%y-%m-%d/%H%M/)  
  23. a1.sinks.k1.hdfs.round = true  
  24. a1.sinks.k1.hdfs.roundValue = 10  
  25. a1.sinks.k1.hdfs.roundUnit = minute  
  26. #目錄裏面有文件  
  27. #------start----兩個條件,只要符合其中一個就滿足---  
  28. #文件滾動之前的等待時間(秒)  
  29. a1.sinks.k1.hdfs.rollInterval = 3  
  30. #文件滾動的大小限制(bytes)  
  31. a1.sinks.k1.hdfs.rollSize = 500  
  32. #寫入多少個event數據後滾動文件(事件個數)  
  33. a1.sinks.k1.hdfs.rollCount = 20  
  34. #-------end-----  
  35.   
  36. #5個事件就往裏面寫入  
  37. a1.sinks.k1.hdfs.batchSize = 5  
  38.   
  39. #用本地時間格式化目錄  
  40. a1.sinks.k1.hdfs.useLocalTimeStamp = true  
  41.   
  42. #下沉後, 生成的文件類型,默認是Sequencefile,可用DataStream,則爲普通文本  
  43. a1.sinks.k1.hdfs.fileType = DataStream  
  44.   
  45. # Use a channel which buffers events in memory  
  46. a1.channels.c1.type = memory  
  47. a1.channels.c1.capacity = 1000  
  48. a1.channels.c1.transactionCapacity = 100  
  49.   
  50. # Bind the source and sink to the channel  
  51. a1.sources.r1.channels = c1  
  52. a1.sinks.k1.channel = c1  

3、shell命令不斷寫數據到文件

[hadoop@nbdo3 testdata]$ while true; do echo "hello ningbo do" >> testflume.log ; sleep 0.5; done


4、在新窗口用tail 命令查看到 testflume.log文件內容不斷增加

[hadoop@nbdo3 testdata]$ tail -f testflume.log 
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do
hello ningbo do


5、啓動hadoop


6、啓動flume

flume-ng agent -c ../conf -flog-hdfs.conf  -n a1 -Dflume.root.logger=INFO,console



7、瀏覽器進入hadoop管理界面。

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