1. 程式人生 > >大資料教程(13.2)Flume多個agent連線

大資料教程(13.2)Flume多個agent連線

   上一節介紹了Flume如何將資料收集到hdfs檔案系統上。本節將分享多個agent連線配合使用。

   原理圖:

    操作步驟:

1、將centos-aaron-h1的flume複製一份到centos-aaron-h2
sudo scp  -r /home/hadoop/apps/apache-flume-1.6.0-bin [email protected]:/home/hadoop/apps/


2、進入centos-aaron-h1的Flume配置目錄
cd ~/apps/apache-flume-1.6.0-bin/conf

3、新建配置檔案
vi tail-avro-avro-logger.conf

4、在上面的配置檔案中新增一下內容

#從tail命令獲取資料傳送到avro埠
#另一個節點可配置一個avro源來中繼資料,傳送外部儲存
##################
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/log/test.log
a1.sources.r1.channels = c1

# Describe the sink
#繫結的不是本機, 是另外一臺機器的服務地址, sink端的avro是一個傳送端, avro的客戶端, 往hadoop01這個機器上發
a1.sinks = k1
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = master
a1.sinks.k1.port = 4141
a1.sinks.k1.batch-size = 2



# 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

5、儲存上面配置
shift+Z+Z

6、建立Flume監聽的檔案所在的資料夾
mkdir /home/hadoop/log

7、創Flume監聽的檔案,並寫迴圈寫入資料
while true
do
echo 111111 >> /home/hadoop/log/test.log
sleep 0.5
done

8、新打開個ssh客戶端執行下列命令檢視日誌檔案變化【使用大寫的-F是追蹤檔名進行輸出,而小寫-f是inode進行追蹤】
tail -F test.log


9、進入centos-aaron-h2的Flume配置目錄
cd ~/apps/apache-flume-1.6.0-bin/conf

10、新建配置檔案
vi avro-hdfs.conf

11、在上面的配置檔案中新增一下內容

#從avro埠接收資料,下沉到logger
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
#source中的avro元件是接收者服務, 繫結本機
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141

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

# 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

12、在centos-aaron-h2啟動flume avro服務
bin/flume-ng agent -c conf -f conf/avro-hdfs.conf -n a1 -Dflume.root.logger=INFO,console

13.在centos-aaron-h1啟動flume avro客戶端
bin/flume-ng agent -c conf -f conf/tail-avro-avro-logger.conf -n a1

 效果圖:

  注意點: Flume如果失敗了,必須要重啟agent程序,它會自動記錄上次採集的位置,繼續採集。大家可以通過寫一個監聽指令碼來實現重啟。最後大家可以參考下《基於Flume的美團日