Flume單數據源多出口案例(Sink組)

今天就在向大家演示一個案例,Flume單源數據多出口案例(注意:此案例是sink組),與我寫的另一篇文章:https://blog.csdn.net/qq_38163244/article/details/105057505略有不同。話不多說,一切用圖說話:

 單Source、Channel多Sink(負載均衡)單Source、Channel多Sink(負載均衡),此圖來自官網哈

我們的需求:使用Flume-1監控文件變動,Flume-1將變動內容傳遞給Flume-2,Flume-2負責存儲到HDFS。同時Flume-1將變動內容傳遞給Flume-3,Flume-3也負責存儲到HDFS,這裏Flume-1是從控制檯輸入數據。

 好了,圖上表達的很明白,source端接收來自控制檯的數據輸入,然後經過channle傳輸到sink端(注意和我上面提到的另一篇文章中的區別),這裏用到的是負載均衡,sink發送數據不會立刻發送到flume-2和flume-3的source端口,這裏是先發送到sink發送器,發送器判斷哪一個flume負載小一點,並且會把數據發送給負載小的哪一個,所以此案例主要講的就是負載均衡這一點,與前一篇文章的選擇器有所不同。

第一步:在flume目錄下面創建job工作目錄,用來存放配置文件,創建flume-netcat-flume.conf,添加以下配置信息:

#在這裏只有一個channel緩存,但是有兩個sink,把他看成一個組
# Name the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinkgroups = g1
a1.sinks = k1 k2

# Describe/configure the source
a1.sources.r1.type = netcat//發送工具
a1.sources.r1.bind = hadoop101//發送數據的端口
a1.sources.r1.port = 44444//發送數據的端口
#sink的類型是負載均衡
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processor.selector = round_robin
a1.sinkgroups.g1.processor.selector.maxTimeOut=10000

# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop101
a1.sinks.k1.port = 4141

a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop101
a1.sinks.k2.port = 4142

# Describe the channel
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.sinkgroups.g1.sinks = k1 k2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1

第二步:創建flume-flume-console1.conf,配置上級Flume輸出的Source,輸出是到本地控制檯。

# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1

# Describe/configure the source
a2.sources.r1.type = avro
a2.sources.r1.bind = hadoop101
a2.sources.r1.port = 4141

# Describe the sink
a2.sinks.k1.type = logger

# Describe the channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1

第三步:創建flume-flume-console2.conf,配置上級Flume輸出的Source,輸出是到本地控制檯。

# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c2

# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = hadoop101
a3.sources.r1.port = 4142

# Describe the sink
a3.sinks.k1.type = logger

# Describe the channel
a3.channels.c2.type = memory
a3.channels.c2.capacity = 1000
a3.channels.c2.transactionCapacity = 100

# Bind the source and sink to the channel
a3.sources.r1.channels = c2
a3.sinks.k1.channel = c2

第四步:執行配置文件

 bin/flume-ng agent -c conf/ -n a3 -f /opt/module/flume-1.7.0/job1/flume-flume-console1.conf -Dflume.root.logger=INFO,console
bin/flume-ng agent -c conf/ -n a3 -f /opt/module/flume-1.7.0/job1/flume-flume-console2.conf-Dflume.root.logger=INFO,console 
 bin/flume-ng agent --conf conf/ --name a1 --conf-file /opt/module/flume-1.7.0/job1/flume-netcat-flume.conf

第五步:我們可以在控制檯輸入內容,可以看到另外兩個控制檯輸出的event包。

現在可以在hadoop101注漿機上面執行nc hadoop101 44444命令就可以向44444端口發送消息了,在flume1和flume2控制檯可以看到輸出。

Notes:使用netcat工具向端口發送數據需要先安裝netcat工具:

sudo yum install -y nc 命令可以直接安裝

sudo netstat -tunlp | grep 44444可以判斷44444端口是否被佔用。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章