標籤:flume
關於failover網上也有很多例子,但是看到的有多重做法,個人覺得,本著職責單一的原則
1、一台機子運行一個flume agent
2、一個agent 的下遊sink指向一個flume agent,不要一個flume agent配置多個連接埠【影響效能】
3、分機子配置,可以避免一台機子司機,另一個仍可以使用,否則陪在一台機子上通過連接埠區分,一旦死機,全盤崩潰
下面看具體執行個體:
首先是flumet agent client的配置
priority越高,優先順序越高,會優先使用該sink
# Name the components on this agenta1.sources = r1a1.sinks = k1 k2a1.channels = c1 # Describe/configure the sourcea1.sources.r1.type = execa1.sources.r1.channels=c1a1.sources.r1.command=tail -F /root/dev/biz/logs/bizlogic.log#define sinkgroupsa1.sinkgroups=g1a1.sinkgroups.g1.sinks=k1 k2a1.sinkgroups.g1.processor.type=failovera1.sinkgroups.g1.processor.priority.k1=10a1.sinkgroups.g1.processor.priority.k2=5a1.sinkgroups.g1.processor.maxpenalty=10000#define the sink 1a1.sinks.k1.type=avroa1.sinks.k1.hostname=192.168.11.179a1.sinks.k1.port=9876#define the sink 2a1.sinks.k2.type=avroa1.sinks.k2.hostname=192.168.11.178a1.sinks.k2.port=9876# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1a1.sinks.k2.channel=c1
這裡可以看到使用了sinkgroup,其中包括了兩個sink,兩個sink分別指向不同的flume agent
再來看flume agent server的配置,即179,178的配置,看一個即可
# Name the components on this agenta1.sources = r1a1.sinks = k1a1.channels = c1 # Describe/configure the sourcea1.sources.r1.type=avro#any address to listena1.sources.r1.bind=0.0.0.0a1.sources.r1.port=9876a1.sources.r1.channels=c1# Describe the sinka1.sinks.k1.type = file_rolla1.sinks.k1.sink.directory=/root/dev/flumeout/filea1.sinks.k1.sink.rollInterval=3600# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1
可以看出flume agent client和server之間是通過avro來傳輸資料的,avro是flume內建的協議,非常方便,可以將flume整個串起來
下面先啟動flume agent server,再啟動flume agent client
測試如下:
for i in {1..100};do echo "exec test tail -f $i on terminator 176" >> bizlogic.log;echo $i;sleep 0.1;done往檔案中寫內容,觸發flume agent client的tail -F,這樣內容就會通過flume agent client 到memory channel中,在通過failover機制選擇優先順序高的sink去輸出,最終輸出的地方,有最後一環的flume配置中sink.type決定,可以看出是file_roll,也就是檔案形式寫到磁碟上,會按照一定方式滾動
起初啟動的時候,178和179都會產生此檔案,但是當你開始產生檔案內容的時候,也還有179才會寫入檔案內容了
至此,完整的flume failover 機制就走通了,共勉!
【Flume】flume 容錯環境的搭建 failover