Flume學習之路 (二)Flume的Source類型


一、概述

官方文檔介紹:http://flume.apache.org/FlumeUserGuide.html#flume-sources

二、Flume Sources 描述

2.1 Avro Source

2.1.1 介紹

監聽Avro端口,從Avro client streams接收events。當與另一個(前一跳)Flume agent內置的Avro Sink配對時,它可以創建分層收集拓撲。字體加粗的屬性必須進行設置

2.1.2 示例

示例一:示例請參考官方文檔

示例二:

#配置一個agent,agent的名稱可以自定義(如a1)
#指定agent的sources(如s1)、sinks(如k1)、channels(如c1)
#分別指定agent的sources,sinks,channels的名稱 名稱可以自定義
a1.sources = s1
a1.sinks = k1
a1.channels = c1

#配置source
a1.sources.s1.channels = c1
a1.sources.s1.type = avro
a1.sources.s1.bind = 192.168.123.102
a1.sources.s1.port = 6666

#配置channels
a1.channels.c1.type = memory

#配置sinks
a1.sinks.k1.channel = c1
a1.sinks.k1.type = logger

#為sources和sinks綁定channels
a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1

啟動flume

[hadoop@hadoop1 ~]$ flume-ng agent --conf conf --conf-file ~/apps/flume/examples/single_avro.properties --name a1 -Dflume.root.logger=DEBUG,console -Dorg.apache.flume.log.printconfig=true -Dorg.apache.flume.log.rawdata=true

通過flume提供的avro客戶端向指定機器指定端口發送日志信息:

[hadoop@hadoop1 ~]$ flume-ng avro-client -c ~/apps/flume/conf -H 192.168.123.102 -p 6666 -F 666.txt

接收到的信息

2.2 Thrift Source

2.2.1 介紹

ThriftSource 與Avro Source 基本一致。只要把source的類型改成thrift即可,例如a1.sources.r1.type = thrift,比較簡單,不做贅述。

2.3 Exec Source

2.3.1 介紹

ExecSource的配置就是設定一個Unix(linux)命令,然后通過這個命令不斷輸出數據。如果進程退出,Exec Source也一起退出,不會產生進一步的數據。

下面是官網給出的source的配置,加粗的參數是必選,描述就不解釋了。

2.3.2 示例

#配置文件
#Name the components on this agent  
a1.sources= s1  
a1.sinks= k1  
a1.channels= c1  
   
#配置sources
a1.sources.s1.type = exec  
a1.sources.s1.command = tail -F /home/hadoop/logs/test.log  
a1.sources.s1.channels = c1  
   
#配置sinks 
a1.sinks.k1.type= logger  
a1.sinks.k1.channel= c1  
   
#配置channel
a1.channels.c1.type= memory  

啟動命令

[hadoop@hadoop1 ~]$ flume-ng agent --conf conf --conf-file ~/apps/flume/examples/case_exec.properties --name a1 -Dflume.root.logger=DEBUG,console -Dorg.apache.flume.log.printconfig=true -Dorg.apache.flume.log.rawdata=true

繼續往日志里添加數據

接收到的信息

2.4 JMS Source

2.4.1 介紹

從JMS系統(消息、主題)中讀取數據,ActiveMQ已經測試過

2.4.2 官網示例

 

2.5 Spooling Directory Source

2.5.1 介紹

Spooling Directory Source監測配置的目錄下新增的文件,並將文件中的數據讀取出來。其中,Spool Source有2個注意地方,第一個是拷貝到spool目錄下的文件不可以再打開編輯,第二個是spool目錄下不可包含相應的子目錄。這個主要用途作為對日志的准實時監控

下面是官網給出的source的配置,加粗的參數是必選。可選項太多,這邊就介紹一個fileSuffix,即文件讀取后添加的后綴名,這個是可以更改。

 

2.5.2 示例

a1.sources = s1  
a1.sinks = k1  
a1.channels = c1  
   
# Describe/configure the source  
a1.sources.s1.type =spooldir  
a1.sources.s1.spoolDir =/home/hadoop/logs  
a1.sources.s1.fileHeader= true  
a1.sources.s1.channels =c1  
   
# Describe the sink  
a1.sinks.k1.type = logger  
a1.sinks.k1.channel = c1  
   
# Use a channel which buffers events inmemory  
a1.channels.c1.type = memory  

啟動命令

[hadoop@hadoop1 ~]$ flume-ng agent --conf conf --conf-file /home/hadoop/apps/flume/examples/case_spool.properties --name a1 -Dflume.root.logger=INFO,console

講123.log移動到logs目錄

運行結果

2.6 其他

參考https://blog.csdn.net/looklook5/article/details/40400885

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM