Flume案例:模拟两个agent之间传递消息的场景
生活随笔
收集整理的這篇文章主要介紹了
Flume案例:模拟两个agent之间传递消息的场景
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
模擬兩個agent之間傳遞消息的場景
說明:
1.在hadoop1機器上有一個flume agent,通過exec監聽tail命令輸出的結果。
2.新增的結果通過avro sink的方式下層到hadoop2:4141的avro source端。
3.在hadoop2機器上有一個flume agent,通過avro source來接收下沉過來的數據。
編寫hadoop1上的通信配置文件
在hadoop1上的flume通信控制的文件tail-avro.conf的內容如下:
#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/tuzq/software/flumedata/test.log a1.sources.r1.channels = c1# Describe the sink ##sink端的avro是一個數據發送者 a1.sinks = k1 ##type設置成avro來設置發消息 a1.sinks.k1.type = avro a1.sinks.k1.channel = c1 ##下沉到hadoop2這臺機器 a1.sinks.k1.hostname = hadoop2 ##下沉到mini2中的4141 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編寫hadoop2上的通信配置文件
在hadoop2上的flume通信控制的文件avro-logger.conf的內容如下:
# 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執行命令,開始測試
進入hadoop1,模擬test.log文件
[root@hadoop1 flumedata]# cd /home/tuzq/software/flumedata [root@hadoop1 flumedata]# while true > do > date >> test.log > sleep 2 > donetail命令查看一下test.log
[root@hadoop1 flumedata]# cd /home/tuzq/software/flumedata [root@hadoop1 flumedata]# tail -f test.log 2017年 06月 14日 星期三 10:21:23 CST 2017年 06月 14日 星期三 10:21:25 CST 2017年 06月 14日 星期三 10:21:27 CST 2017年 06月 14日 星期三 10:21:29 CST 2017年 06月 14日 星期三 10:21:31 CST 2017年 06月 14日 星期三 10:21:33 CST 2017年 06月 14日 星期三 10:21:35 CST 2017年 06月 14日 星期三 10:21:37 CST 2017年 06月 14日 星期三 10:21:39 CST 2017年 06月 14日 星期三 10:21:41 CST 2017年 06月 14日 星期三 10:21:43 CST啟動hadoop2上的flume agent
由于hadoop1上的agent配置文件中配置下沉的位置是hadoop2:4141,所以需要先啟動hadoop2上的flume agent
啟動命令是:
啟動效果圖如下:
啟動hadoop1上的flume agent
[root@hadoop1 agentconf]# bin/flume-ng agent -c conf -f agentconf/tail-avro.conf -n a1 -Dflume.root.logger=INFO,console啟動信息:
查看hadoop2上的運行效果
通過上圖發現只要test.log中有日志文件變化,在hadoop2上的agent就會有響應結果
總結
以上是生活随笔為你收集整理的Flume案例:模拟两个agent之间传递消息的场景的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 糖尿病人打胰岛素血糖还是高该怎么办(表嫂
- 下一篇: 花园宝宝人物名字英文(花园宝宝 里 人物