溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Flume NG 學(xué)習(xí)筆記(三)流配置

發(fā)布時間:2020-06-16 14:10:15 來源:網(wǎng)絡(luò) 閱讀:933 作者:jackwxh 欄目:開發(fā)技術(shù)

目錄(?)[+]

Flume NG 學(xué)習(xí)筆記(三)流配置


在通過flume采集日志數(shù)據(jù)的時候,一般都是通過flume 代理從日志源或者日志客戶端采集數(shù)據(jù)到flume代理中,然后再由flume代理送到目標(biāo)存儲.上圖中就是每個一級flume代理負(fù)責(zé)從webserv采集數(shù)據(jù),然后再由一個二級flume代理進(jìn)行日志匯總。

Flume NG 學(xué)習(xí)筆記(三)流配置


Flume支持從一個源發(fā)送事件到多個通道中,這被稱為事件流的復(fù)用。這里需要在配置中定義事件流的復(fù)制/復(fù)用,選擇1個或者多個通道進(jìn)行數(shù)據(jù)流向。

下面的內(nèi)容主要介紹flume 流配置,這節(jié)比較水,因為都比較簡單。

一、單一代理流配置

下面的配置例子是外部數(shù)據(jù)源通過avro客戶端發(fā)送數(shù)據(jù)到HDFS上。下面無節(jié)操的直接拷官網(wǎng)


[html] view plain copy

  1. agent_foo.sourcesavro-AppSrv-source  

  2. agent_foo.sinkshdfs-Cluster1-sink  

  3. agent_foo.channelsmem-channel-1  

  4.    

  5. # set channel for sources, sinks  

  6.    

  7. # properties of avro-AppSrv-source  

  8. agent_foo.sources.avro-AppSrv-source.typeavro  

  9. agent_foo.sources.avro-AppSrv-source.bindlocalhost  

  10. agent_foo.sources.avro-AppSrv-source.port10000  

  11.    

  12. # properties of mem-channel-1  

  13. agent_foo.channels.mem-channel-1.typememory  

  14. agent_foo.channels.mem-channel-1.capacity1000  

  15. agent_foo.channels.mem-channel-1.transactionCapacity100  

  16.    

  17. # properties of hdfs-Cluster1-sink  

  18. agent_foo.sinks.hdfs-Cluster1-sink.typehdfs  

  19. agent_foo.sinks.hdfs-Cluster1-sink.hdfs.pathhdfs://namenode/flume/webdata  



二、單代理多流配置

單代理多流配置是上面的加強版,相當(dāng)于一個代理兩個流,一個是從外部avro客戶端到HDFS,另一個是Linux命令(tail)的輸出到Avro接受代理,2個做成配置。繼續(xù)無節(jié)操的直接拷官網(wǎng)


[html] view plain copy

  1. # list the sources, sinks and channelsin the agent  

  2. agent_foo.sourcesavro-AppSrv-source1 exec-tail-source2  

  3. agent_foo.sinkshdfs-Cluster1-sink1 avro-forward-sink2  

  4. agent_foo.channelsmem-channel-1 file-channel-2  

  5.    

  6. # flow #1 configuration  

  7. agent_foo.sources.avro-AppSrv-source1.channelsmem-channel-1  

  8. agent_foo.sinks.hdfs-Cluster1-sink1.channelmem-channel-1  

  9.    

  10. # flow #2 configuration  

  11. agent_foo.sources.exec-tail-source2.channelsfile-channel-2  

  12. agent_foo.sinks.avro-forward-sink2.channelfile-channel-2  




三、配置多代理流程

這個配置就是學(xué)習(xí)(二)的第二個例子,簡單的講就是數(shù)據(jù)源發(fā)送的事件由第一個Flume代理發(fā)送到下一個Flume代理中。下面是官網(wǎng):


[html] view plain copy

  1. # list sources, sinks and channels inthe agent  

  2. agent_foo.sourcesavro-AppSrv-source  

  3. agent_foo.sinksavro-forward-sink  

  4. agent_foo.channelsfile-channel  

  5.    

  6. # define the flow  

  7. agent_foo.sources.avro-AppSrv-source.channelsfile-channel  

  8. agent_foo.sinks.avro-forward-sink.channelfile-channel  

  9.    

  10. # avro sink properties  

  11. agent_foo.sources.avro-forward-sink.typeavro  

  12. agent_foo.sources.avro-forward-sink.hostname10.1.1.100  

  13. agent_foo.sources.avro-forward-sink.port10000  

  14.    

  15. # configure other pieces  

  16. #...  



例子都不難理解

四、多路復(fù)用流

Flume支持從一個源到多個通道和sinks,叫做fan out。有兩種模式的fan out,復(fù)制和復(fù)用。復(fù)制就是流的事件被發(fā)送到所有的配置通道去。


[html] view plain copy

  1. # List the sources, sinks and channelsfor the agent  

  2. <Agent>.sources<Source1>  

  3. <Agent>.sinks<Sink1> <Sink2>  

  4. <Agent>.channels<Channel1> <Channel2>  

  5.    

  6. # set list of channels for source(separated by space)  

  7. <Agent>.sources.<Source1>.channels<Channel1> <Channel2>  

  8.    

  9. # set channel for sinks  

  10. <Agent>.sinks.<Sink1>.channel<Channel1>  

  11. <Agent>.sinks.<Sink2>.channel<Channel2>  

  12.    

  13. <Agent>.sources.<Source1>.selector.typereplicating  

其中,<Agent>.sources.<Source1>.selector.type= replicating 這個源的選擇類型為復(fù)制。這個參數(shù)不指定一個選擇的時候,默認(rèn)情況下它復(fù)制


復(fù)用則是麻煩一下,流的事情是被篩選的發(fā)生到不同的渠道,需要指定源和扇出通道的規(guī)則,感覺與case when 類似。

復(fù)用的參數(shù)為:<Agent>.sources.<Source1>.selector.type = multiplexing


[html] view plain copy

  1. # Mapping for multiplexing selector  

  2. <Agent>.sources.<Source1>.selector.typemultiplexing  

  3. <Agent>.sources.<Source1>.selector.header<someHeader>  

  4. <Agent>.sources.<Source1>.selector.mapping.<Value1><Channel1>  

  5. <Agent>.sources.<Source1>.selector.mapping.<Value2><Channel1> <Channel2>  

  6. <Agent>.sources.<Source1>.selector.mapping.<Value3><Channel2>  

  7. #...  

  8.    

  9. <Agent>.sources.<Source1>.selector.default<Channel2>  



官網(wǎng)中給出例子,可以看出流的事件要聲明一個頭部,然后我們檢查頭部對應(yīng)的值,這里我們可以認(rèn)為是事件屬性,如果指定的值與設(shè)定的通道相匹配,那么就將該事件發(fā)送到被匹配到的通道中去。這個參數(shù)就是默認(rèn)通道<Agent>.sources.<Source1>.selector.default =<Channel2>

下面是官網(wǎng)中復(fù)用的詳細(xì)配置例子


[html] view plain copy

  1. # list the sources, sinks and channelsin the agent  

  2. agent_foo.sourcesavro-AppSrv-source1  

  3. agent_foo.sinkshdfs-Cluster1-sink1 avro-forward-sink2  

  4. agent_foo.channelsmem-channel-1 file-channel-2  

  5.    

  6. # set channels for source  

  7. agent_foo.sources.avro-AppSrv-source1.channelsmem-channel-1 file-channel-2  

  8.    

  9. # set channel for sinks  

  10. agent_foo.sinks.hdfs-Cluster1-sink1.channelmem-channel-1  

  11. agent_foo.sinks.avro-forward-sink2.channelfile-channel-2  

  12.    

  13. # channel selector configuration  

  14. agent_foo.sources.avro-AppSrv-source1.selector.typemultiplexing  

  15. agent_foo.sources.avro-AppSrv-source1.selector.headerState  

  16. agent_foo.sources.avro-AppSrv-source1.selector.mapping.CAmem-channel-1  

  17. agent_foo.sources.avro-AppSrv-source1.selector.mapping.AZfile-channel-2  

  18. agent_foo.sources.avro-AppSrv-source1.selector.mapping.NYmem-channel-1 file-channel-2  

  19. agent_foo.sources.avro-AppSrv-source1.selector.defaultmem-channel-1  



上面例子中,設(shè)置事件的頭屬性Header 為“State”作為的選擇檢查。剩下的就是與case when 基本一樣。其中,例子中的配置

agent_foo.sources.avro-AppSrv-source1.selector.mapping.NY= mem-channel-1 file-channel-2 從這里可以看出映射允許每個值通道可以重疊。默認(rèn)值可以包含任意數(shù)量的通道。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI