您好,登錄后才能下訂單哦!
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
目錄(?)[+]
在通過flume采集日志數(shù)據(jù)的時候,一般都是通過flume 代理從日志源或者日志客戶端采集數(shù)據(jù)到flume代理中,然后再由flume代理送到目標(biāo)存儲.上圖中就是每個一級flume代理負(fù)責(zé)從webserv采集數(shù)據(jù),然后再由一個二級flume代理進(jìn)行日志匯總。
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
agent_foo.sources= avro-AppSrv-source
agent_foo.sinks= hdfs-Cluster1-sink
agent_foo.channels= mem-channel-1
# set channel for sources, sinks
# properties of avro-AppSrv-source
agent_foo.sources.avro-AppSrv-source.type= avro
agent_foo.sources.avro-AppSrv-source.bind= localhost
agent_foo.sources.avro-AppSrv-source.port= 10000
# properties of mem-channel-1
agent_foo.channels.mem-channel-1.type= memory
agent_foo.channels.mem-channel-1.capacity= 1000
agent_foo.channels.mem-channel-1.transactionCapacity= 100
# properties of hdfs-Cluster1-sink
agent_foo.sinks.hdfs-Cluster1-sink.type= hdfs
agent_foo.sinks.hdfs-Cluster1-sink.hdfs.path= hdfs://namenode/flume/webdata
單代理多流配置是上面的加強版,相當(dāng)于一個代理兩個流,一個是從外部avro客戶端到HDFS,另一個是Linux命令(tail)的輸出到Avro接受代理,2個做成配置。繼續(xù)無節(jié)操的直接拷官網(wǎng)
[html] view plain copy
# list the sources, sinks and channelsin the agent
agent_foo.sources= avro-AppSrv-source1 exec-tail-source2
agent_foo.sinks= hdfs-Cluster1-sink1 avro-forward-sink2
agent_foo.channels= mem-channel-1 file-channel-2
# flow #1 configuration
agent_foo.sources.avro-AppSrv-source1.channels= mem-channel-1
agent_foo.sinks.hdfs-Cluster1-sink1.channel= mem-channel-1
# flow #2 configuration
agent_foo.sources.exec-tail-source2.channels= file-channel-2
agent_foo.sinks.avro-forward-sink2.channel= file-channel-2
這個配置就是學(xué)習(xí)(二)的第二個例子,簡單的講就是數(shù)據(jù)源發(fā)送的事件由第一個Flume代理發(fā)送到下一個Flume代理中。下面是官網(wǎng):
[html] view plain copy
# list sources, sinks and channels inthe agent
agent_foo.sources= avro-AppSrv-source
agent_foo.sinks= avro-forward-sink
agent_foo.channels= file-channel
# define the flow
agent_foo.sources.avro-AppSrv-source.channels= file-channel
agent_foo.sinks.avro-forward-sink.channel= file-channel
# avro sink properties
agent_foo.sources.avro-forward-sink.type= avro
agent_foo.sources.avro-forward-sink.hostname= 10.1.1.100
agent_foo.sources.avro-forward-sink.port= 10000
# configure other pieces
#...
例子都不難理解
Flume支持從一個源到多個通道和sinks,叫做fan out。有兩種模式的fan out,復(fù)制和復(fù)用。復(fù)制就是流的事件被發(fā)送到所有的配置通道去。
[html] view plain copy
# List the sources, sinks and channelsfor the agent
<Agent>.sources= <Source1>
<Agent>.sinks= <Sink1> <Sink2>
<Agent>.channels= <Channel1> <Channel2>
# set list of channels for source(separated by space)
<Agent>.sources.<Source1>.channels= <Channel1> <Channel2>
# set channel for sinks
<Agent>.sinks.<Sink1>.channel= <Channel1>
<Agent>.sinks.<Sink2>.channel= <Channel2>
<Agent>.sources.<Source1>.selector.type= replicating
其中,<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
# Mapping for multiplexing selector
<Agent>.sources.<Source1>.selector.type= multiplexing
<Agent>.sources.<Source1>.selector.header= <someHeader>
<Agent>.sources.<Source1>.selector.mapping.<Value1>= <Channel1>
<Agent>.sources.<Source1>.selector.mapping.<Value2>= <Channel1> <Channel2>
<Agent>.sources.<Source1>.selector.mapping.<Value3>= <Channel2>
#...
<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
# list the sources, sinks and channelsin the agent
agent_foo.sources= avro-AppSrv-source1
agent_foo.sinks= hdfs-Cluster1-sink1 avro-forward-sink2
agent_foo.channels= mem-channel-1 file-channel-2
# set channels for source
agent_foo.sources.avro-AppSrv-source1.channels= mem-channel-1 file-channel-2
# set channel for sinks
agent_foo.sinks.hdfs-Cluster1-sink1.channel= mem-channel-1
agent_foo.sinks.avro-forward-sink2.channel= file-channel-2
# channel selector configuration
agent_foo.sources.avro-AppSrv-source1.selector.type= multiplexing
agent_foo.sources.avro-AppSrv-source1.selector.header= State
agent_foo.sources.avro-AppSrv-source1.selector.mapping.CA= mem-channel-1
agent_foo.sources.avro-AppSrv-source1.selector.mapping.AZ= file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.mapping.NY= mem-channel-1 file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.default= mem-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ù)量的通道。
免責(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)容。