案例需求:
首先Flume监控本机44444端口,然后通过telnet工具向本机
端口发送信息,最后Flume将监听的数据实时显示在控制台。
实现步骤:
1.安装telnet工具
sudo rpm -ivh xinetd-2.3.14-40.el6.x86_64.rpm
sudo rpm -ivh telnet-0.17-48.el6.x86_64.rpm
sudo rpm -ivh telnet-server-0.17-48.el6.x86_64.rpm
2.判断44444端口是否被占用
sudo netstat -tunlp | grep 44444
功能描述:
netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示
路由表、实际的网络连接以及每一个网络接口设备的状态信息。
基本语法:netstat [选项]
选项参数:
-t或--tcp:显示TCP传输协议的连线状况;
-u或--udp:显示UDP传输协议的连线状况;
-n或--numeric:直接使用ip地址,而不通过域名服务器;
-l或--listening:显示监控中的服务器的Socket;
-p或--programs:显示正在使用Socket的程序识别码和程序名称;
3.创建FlumeAgent配置文件"flume-telnet-logger.conf"
在flume目录下创建job文件夹并进入job文件夹。
mkdir job
cd job/
在job文件夹下创建Flume Agent配置文件flume-telnet-logger.conf。
touch flume-telnet-logger.conf
在flume-telnet-logger.conf文件中添加如下内容。
vim flume-telnet-logger.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
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# 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
注:配置文件来源于官方手册http://flume.apache.org/FlumeUserGuide.html
4.先开启flume监听端口
bin/flume-ng agent --conf conf/ --name a1
--conf-file job/flume-telnet-logger.conf -Dflume.root.logger=INFO,console
参数说明:
--conf conf/ :表示配置文件存储在conf/目录
--name a1 :表示给agent起名为a1
--conf-file job/flume-telnet.conf :flume本次启动读取的配置文件是在job文件夹下的flume-telnet.conf文件。
-Dflume.root.logger==INFO,console :-D表示flume运行时动态修改flume.root.logger参数属性值,
并将控制台日志打印级别设置为INFO级别。日志级别包括:log、info、warn、error。
5.使用telnet工具向本机44444端口发送内容
telnet localhost 44444
6.在flume监听页面观察接收数据情况
再开一个node01即可