1. 程式人生 > >【Flume】flume 容錯環境的搭建 failover

【Flume】flume 容錯環境的搭建 failover

關於failover網上也有很多例子,但是看到的有多重做法,個人覺得,本著職責單一的原則

1、一臺機子執行一個flume agent

2、一個agent 的下游sink指向一個flume agent,不要一個flume agent配置多個埠【影響效能】

3、分機子配置,可以避免一臺機子司機,另一個仍可以使用,否則陪在一臺機子上通過埠區分,一旦宕機,全盤崩潰

下面看具體例項:

首先是flumet agent client的配置

priority越高,優先順序越高,會優先使用該sink

# Name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1
 
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.channels=c1
a1.sources.r1.command=tail -F /root/dev/biz/logs/bizlogic.log

#define sinkgroups
a1.sinkgroups=g1
a1.sinkgroups.g1.sinks=k1 k2
a1.sinkgroups.g1.processor.type=failover
a1.sinkgroups.g1.processor.priority.k1=10
a1.sinkgroups.g1.processor.priority.k2=5
a1.sinkgroups.g1.processor.maxpenalty=10000

#define the sink 1
a1.sinks.k1.type=avro
a1.sinks.k1.hostname=192.168.11.179
a1.sinks.k1.port=9876

#define the sink 2
a1.sinks.k2.type=avro
a1.sinks.k2.hostname=192.168.11.178
a1.sinks.k2.port=9876


# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
a1.sinks.k2.channel=c1
這裡可以看到使用了sinkgroup,其中包括了兩個sink,兩個sink分別指向不同的flume agent

再來看flume agent server的配置,即179,178的配置,看一個即可

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
 
# Describe/configure the source
a1.sources.r1.type=avro
#any address to listen
a1.sources.r1.bind=0.0.0.0
a1.sources.r1.port=9876
a1.sources.r1.channels=c1

# Describe the sink
a1.sinks.k1.type = file_roll
a1.sinks.k1.sink.directory=/root/dev/flumeout/file
a1.sinks.k1.sink.rollInterval=3600


# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.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 機制就走通了,共勉!