您的位置:首页 > 其它

Flume案例:模拟两个agent之间传递消息的场景

2017-06-14 11:16 375 查看

模拟两个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
> done


tail命令查看一下test.log

[root@hadoop1 flumedata]# cd 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

启动命令是:

[root@hadoop2 apache-flume-1.6.0-bin]# pwd
/home/tuzq/software/apache-flume-1.6.0-bin
[root@hadoop2 apache-flume-1.6.0-bin]# ls
agentconf  bin  CHANGELOG  conf  DEVNOTES  docs  lib  LICENSE  NOTICE  README  RELEASE-NOTES  tools
[root@hadoop2 apache-flume-1.6.0-bin]# cd agentconf/
[root@hadoop2 agentconf]# ls
avro-logger.conf
[root@hadoop2 agentconf]#
[root@hadoop2 apache-flume-1.6.0-bin]# bin/flume-ng agent -c conf -f agentconf/avro-logger.conf -n a1 -Dflume.root.logger=INFO,console


启动效果图如下:



启动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就会有响应结果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: