案例一【监控端口数据】
目标:Flume监控一端Console(控制台),另一端Console发送消息,使被监控端实时显示。
分步实现:
1.创建Flume Agent配置文件flume-telnet.conf
1)创建自己的配置文件
[root@bigdata111 flume-1.8.0]# mkdir myconf
自己创建Flume Agent配置文件flume-telnet.conf
[root@bigdata111 myconf]# vi flume-telnet.conf
2)填写配置文件
进去之后一定要先按i,进入编辑模式后再粘贴,否则可能会丢失一些东西,配置内容如下:
#定义Agent a1.sources = r1 a1.sinks = k1 a1.channels = c1
#定义netcatsource-端口的source源,只能接受本地的源 a1.sources.r1.type = netcat a1.sources.r1.bind = bigdata111 #监控的端口号 a1.sources.r1.port = 44445
# 定义sink-写到日志里 a1.sinks.k1.type = logger
# 定义channel--官方默认的 #小,可直接在内存中传输 a1.channels.c1.type = memory #管道的容量 a1.channels.c1.capacity = 1000 #每次Sink可以最多拿多少数据,必须小于上一行的值 a1.channels.c1.transactionCapacity = 100
# 双向链接 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 |
2.启动flume配置文件
1)第一种启动flume的方法--详写版
[root@bigdata111 myconf]# flume-ng agent \
> --conf /opt/module/flume-1.8.0/conf/ \
> --name a1 \
> --conf-file flume-telnet.conf \
> -Dflume.root.logger==INFO,console
2)第二种启动flume的方法--简写版
#启动一个agent --指定flume官方的conf --指定agent的名字 --指定配置文件
bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/flume-telnet.conf
#想打印日志就写下面的命令
-Dflume.root.logger==INFO,console
[root@bigdata112 ~]# telnet
-bash: telnet: command not found(这说明需要安装与telnet命令相关的安装包)
查看telnet命令所在的包名
[root@bigdata112 ~]# yum search telnet
======================= N/S matched: telnet =======================
telnet.x86_64 : The client program for the Telnet remote login : protocol
telnet-server.x86_64 : The server program for the Telnet remote : login protocol tn5250.i686 : 5250 Telnet protocol and Terminal
tn5250.x86_64 : 5250 Telnet protocol and Terminal
Name and summary matches only, use "search all" for everything.
下载此工具包:
[root@bigdata112 ~]# yum -y install telnet
4.使用telnet工具向本机的44445端口发送内容
[root@bigdata112 ~]# telnet bigdata111 44445
Trying 192.168.212.111...
Connected to bigdata111.
Escape character is '^]'.
Hello Flume(回车之后会显示OK,表明发送成功,回车可以接着输入)
之后到bigdata111上查看:
Event: { headers:{} body: 48 65 6C 6C 6F 20 46 6C 75 6D 65 0D Hello Flume. }
这代表第一个案例检测成功。
停止悬停就按:CTRL+c,停止bigdata111后bigdata112就自动也停止了。