案例一【監控端口數據】
目標: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就自動也停止了。