整体架构如下图,有两台服务器,在服务器之间传输一般用avro 或者Thrift比较多,这里选择avro source和sink:
一、Flume配置
1.在A服务器新建aserver.conf
#服务器A(192.168.116.10)
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 配置监控文件
a1.sources.r1.type = exec
a1.sources.r1.command =tail -F /usr/tmp/flume/1.log
a1.sources.r1.shell = /bin/sh -c
# 配置sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname=192.168.116.11
a1.sinks.k1.port = 44444
# 配置channel
a1.channels.c1.type = memory
# 将三者串联
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2.在B服务器新建bserver.conf
#服务器B(192.168.116.11)
b1.sources = r2
b1.sinks = k2
b1.channels = c2
# 配置监控文件
b1.sources.r2.type = avro
b1.sources.r2.bind=192.168.116.11
b1.sources.r2.port = 44444
#b1.sources.r2.interceptors = i1
#b1.sources.r2.interceptors.i1.type = timestamp
# 配置sink
b1.sinks.k2.type =logger
# 配置channel
b1.channels.c2.type = memory
# 将三者串联
b1.sources.r2.channels = c2
b1.sinks.k2.channel = c2
~
二、测试
1.先启动bserver.conf
flume-ng agent -n b1 -c /usr/local/src/apache-flume-1.6.0-bin/conf -f /usr/local/src/apache-flume-1.6.0-bin/conf/bserver.conf -Dflume.root.logger=INFO,console
2.再启动aserver.conf
flume-ng agent -n a1 -c /usr/local/src/apache-flume-1.6.0-bin/conf -f /usr/local/src/apache-flume-1.6.0-bin/conf/aserver.conf -Dflume.root.logger=INFO,console
往监控文件里面添加东西
可以看到控制台已经监控到内容了。
把sink改成hdfs就可以采集到hdfs上了
三、踩坑说明
1.启动顺序,一定要先启动B服务器再启动A服务器
2.如果遇到报错
[ERROR - org.apache.flume.lifecycle.LifecycleSupervisor$MonitorRunnable.run(LifecycleSupervisor.java:253)] Unable to start EventDrivenSourceRunner: { source:Avro source r1: { bindAddress: master, port: 44444 } } - Exception follows.
org.jboss.netty.channel.ChannelException: Failed to bind to: master/192.168.116.10:44444
Caused by: java.net.BindException: Cannot assign requested address
这说明你的IP地址配置错了,要配置成B服务器的,不是A服务器的。
3.如果启动成功,但是没有监控到内容输出
可能是flume的配置错了,比如avro source 和avro sink 的ip配置是不一样的,一个叫做hostname,一个叫做bind,,这个坑了我很久才注意到。