source介紹及動手實踐

flume內置了大量的source,其中avro source、thrift source、spooling directory source、kafka source具有較好的性能和較廣泛的使用場景。

avro source
Avro Source監聽Avro端口,接收外部Avro客戶端發送過來的Avro Event數據。在多級流中,Avro Source可以和前一個Flume Agent的Avro Sink配對,建立分層收集拓撲。Avro Source的配置如下表所示,表中只列出必填項,即type、channels、bind、port
a1.sources = r1#a1中的Source
a1.channels = c1 #a1中的Channel 
a1.sources.r1.type = avro #Source的類型 
a1.sources.r1.channels = c1 #指定Source r1數據發送到的Channel 
a1.sources.r1.bind = 0.0.0.0#Source綁定的地址
a1.sources.r1.port = 4141#Source監聽的端口

thrift source
Thrift Source監聽Thrift端口,接收外部Thrift客戶端發送過來的Thrift Event數據。在多級流中,Thrift Source可以和前一個Flume Agent的Thrift Sink配對,建立分層收集拓撲。Thrift Source支持基於Kerberos身份驗證的安全模式。Thrift Source的配置如下表所示,表中只列出必填項,即type、channels、bind、port。Thrift Source支持基於Kerberos身份驗證的安全模式。
a1.sources = r1#a1中的Source 
a1.channels = c1 #a1中的Channel 
a1.sources.r1.type = thrift #Source的類型
a1.sources.r1.channels = c1 #指定Source r1數據發送到的Channel 
a1.sources.r1.bind = 0.0.0.0#Source綁定的地址
a1.sources.r1.port = 4141#Source監聽的端口

exec source
Exec Source在啓動時調用的Unix命令,該命令進程會持續地把標準日誌數據輸出到Exec Source,如果命令進程關閉,Exec Source也會關閉。Exec Source支持cat [named pipe]或者tail -F [file]命令。Exec Source最大的問題就是數據有可能丟失,因爲當Channel接收Exec Source數據出錯時或者拋出異常時,Exec Client並不能捕獲到該錯誤。建議使用Spooling Directory Source代替。表中只列出必填項,type、channels、command。
a1.sources = r1 
a1.channels = c1 
a1.sources.r1.type = exec 
a1.sources.r1.command = tail -F /var/log/secure
a1.sources.r1.channels = c1

jms source
JMS Source從隊列或者Topic中讀取數據,目前只在ActiveMQ中測試。在使用JMS Source時,必須在Flume ClassPath中添加JMS JAR包
channels、type、initialContextFactory、connectionFactory、providerURL、destinationName、destinationType必填項。
a1.sources = r1 
a1.channels = c1 
a1.sources.r1.type = jms 
a1.sources.r1.channels = c1 
a1.sources.r1.initialContextFactory = org.apache.activemq.jndi.ActiveMQInitialContextFactory 
a1.sources.r1.connectionFactory = GenericConnectionFactory 
a1.sources.r1.providerURL = tcp://mqserver:61616 
a1.sources.r1.destinationName = BUSINESS_DATA 
a1.sources.r1.destinationType = QUEUE

spooling directory source
Spooling Directory Source監聽系統上的指定目錄,當目錄中有新的文件創建時,Spooling Directory Source會把新文件的內容讀取並推送到Channel中,並且把已讀取的文件重命名成指定格式或者把文件刪除。由於數據是以文件的形式存放的系統中,Spooling Directory Source的可靠性非常高,即使是Flume Agent崩潰或者重啓,數據也可以恢復。channels、type、spoolDir爲必填項
注意:
1、拷貝到spool指定的目錄下的文件不可再打開編輯
2、spool目錄下不可有子目錄
a1.sources = s1 #a1中的Source 
a1.channels = c1 #a1中的Channel 
a1.sources.s1.type = spooldir #Source的類型 
a1.sources. s1.channels = c1 #指定Source r1數據發送到的Channel 
a1.sources. s1.spoolDir = /var/log/apache/flumeSpool
kafka source
Kafka Source從消息隊列Kafka Topic中讀取日誌消息,Kafka Source相當於消息隊列的Consumer。可以把多個Kafka Source配置到同一個分組裏面,這樣每個Source都可以讀取同一個Topic中的數據,從而提高性能。channels、type、zookeeperConnect、groupId、topic爲必填項
a1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.source1.channels = channel1
a1.sources.source1.zookeeperConnect = localhost:2181
a1.sources.source1.topic = test1
a1.sources.source1.groupId = flume
a1.sources.source1.kafka.consumer.timeout.ms = 100

netcat source
NetCat Source監聽指定的端口,把接收到的數據按行劃分,每行文本都封裝成一個Event數據發送給Channel。type、bind、port爲必填項a1.sources = r1 
a1.channels = c1 
a1.sources.r1.type = netcat 
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.bind = 6666 
a1.sources.r1.channels = c1

http source

HTTP Source接收POST和GET發送的Event數據,其中GET主要用戶測試,不建議生產環境使用。HTTP數據通過handler(實現HTTPSourceHandler接口)轉換成Event,該handler接收HttpServletRequest並返回Event數組。如果handler出現異常,HTTP Source返回400錯誤。如果Channel滿了或者Channel無法接收Event,HTTP Source返回503錯誤。channels、type、port、org.apache.flume.source.http爲必填項
a1.sources = r1 a1.channels = c1 a1.sources.r1.type = http a1.sources.r1.port = 5140 a1.sources.r1.channels = c1 a1.sources.r1.handler = org.example.rest.RestHandler a1.sources.r1.handler.nickname = random props


syslog source
讀取syslog數據,並生成flume event,UDP source將整個消息作爲一個單一的event,TCP source爲每一個用回車來分隔的字符串創建一個新的事件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章