假设:现有两台机子,命名为:agent,collect。agent IP地址为:192.168.150.137,collect为192.168.150.135
要求:实现agent到collect的连接,并能向collect发送日志。
步骤:
两台电脑上分别装上 jdk,flume-ng(不是flume-og),配置好profile。具体参见百度。
agent的处理
(1)找到flume-ng安装目录下的conf文件夹,新建test.conf
#name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat //这里的数据源设置成netcat,后面将通过telnet传送信息
a1.sources.r1.bind = 0.0.0.0 //建议
a1.sources.r1.port = 44444
# Describe the sink
a1.sinks.k1.type =avro
a1.sinks.k1.hostname=192.168.150.135 //collect 的IP地址,注意
a1.sinks.k1.port=60000 //这里的接口要与collect source的接口一致。
# 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
设置好后,暂时不要开启agent。
3.下面设置collect,同agent,新建test.conf 文件
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.bind = 192.168.150.135 //绑定本机的IP的地址
a1.sources.r1.port =60000 //接口要与agent sink的port一致
# 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
4.设置好之后保存退出,输入命令:(当前目录为$FLUME_HOME/conf)
flume-ng agent -n a1 -c conf -f test.conf,若没有问题在agent机上输入命令:
flume-ng agent -c conf -f test.conf -n a1 -Dflume.root.logger=INFO,console
collect机上会出现:
则表示没有问题。
进入下一步
5.在agent另开一个 terminal,输入 telnet 127.0.0.1 44444 后(需要安装,yum install telnet)
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
然后就可以输入如:ss,enter后到collect机上查看
刚学Linux 和flume没几天,有不足还请指教,多多交流,充分发挥开源中国的作用。