3.1 官方案例:监控端口数据

这是一个单节点的案例

3.1.1 案例需求

首先,Flume 监控本机 44444 端口,然后通过 telnet 工具向本机 44444 端口发送消息,最后 Flume 将监听的数据实时显示在控制台。

3.1.2 操作步骤

步骤1: 安装 telnet 工具

将 rpm 软件包(xinetd-2.3.14-40.el6.x86_64.rpm、telnet-0.17-48.el6.x86_64.rpm和telnet-server-0.17-48.el6.x86_64.rpm)拷入 /opt/software 文件夹下面。 执行RPM软件包安装命令:

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: 判断 444 端口是否被占用

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: 创建 Flume Agent 配置文件 flume-telnet-logger.conf

配置文件名, 和配置文件所在的路径都是随意没有强制要求的.
但是最好名字应该体现业务需求, 放置配置文件的目录可以放在 Flume 的根目录下.

cd /opt/module/flume
mkdir job  # 创建 job 目录
cd job
touch flume-telnet-logger.conf  # 创建配置文件

在配置文件内添加如下内容:

# example.conf: A single-node Flume configuration

# Name the components on this agent  给这个 agent 的组件命名
# a1 就是这个 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

步骤4: 开启 Flume, 开始监听 44444 端口

bin/flume-ng agent --conf conf/ --conf-file job/flume-telnet-logger.conf --name a1 -Dflume.root.logger=INFO,console

说明:

  • --conf conf/ 表示配置文件所在的目录(-c conf/)
  • --conf-file job/flume-telnet-logger.conf 表示配置文件的文件名(-f job/flume-telnet-logger.conf)
  • --name a1 表示 agent 的名字(-n a1)
  • -Dflume.root.logger=INFO,console 表示 flume 运行时动态修改flume.root.logger参数属性值,并将控制台日志打印级别设置为INFO级别。日志级别包括:log、info、warn、error。 注意: INFO,console中的逗号后面不能添加空格.

步骤5: 使用 telnet 工具向本机的 44444 端口发送内容

telnet localhost 44444

Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2018-12-17 14:44:53

results matching ""

    No results matching ""