Flume基础知识(三):Flume 实战监控端口数据官方案例

发布时间:2024年01月03日

1. 监控端口数据官方案例

1)案例需求:

使用 Flume 监听一个端口,收集该端口数据,并打印到控制台。

2)需求分析:

3)实现步骤:

(1)安装 netcat 工具

sudo yum install -y nc

(2)判断 44444 端口是否被占用

sudo netstat -nlp | grep 44444

(3)创建 Flume Agent 配置文件 flume-netcat-logger.conf

(4)在 flume 目录下创建 job 文件夹并进入 job 文件夹。

mkdir job
cd job/

(5)在 job 文件夹下创建 Flume Agent 配置文件 flume-netcat-logger.conf。

touch net-flume-logger.conf

(6)在 flume-netcat-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

注:配置文件来源于官方手册 Flume 1.11.0 User Guide — Apache Flume

同一台机器中,不能配置多个相同的a1.事务的容量要比总容量要小,也就是说a1.channels.c1.transactionCapacity < a1.channels.c1.capacity,一个source可以绑定多个channel,一个channel只能发到一个sink。

(7)先开启 flume 监听端口 第一种写法:

bin/flume-ng agent -n a1 -c conf/ -f job/net-flume-logger.conf -Dflume.root.logger=INFO,console

第二种写法:

bin/flume-ng agent -c conf/ -n a1 -f  job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console

参数说明

--conf/-c:表示配置文件存储在 conf/目录

--name/-n:表示给 agent 起名为 a1

--conf-file/-f:flume 本次启动读取的配置文件是在 job 文件夹下的 flume-telnet.conf 文件。

-Dflume.root.logger=INFO,console :-D 表示 flume 运行时动态修改 flume.root.logger 参数属性值,并将控制台日志打印级别设置为 INFO 级别。日志级别包括:log、info、warn、 error。

(8)使用 netcat 工具向本机的 44444 端口发送内容

nc localhost 44444

(9)在 Flume 监听页面观察接收数据情况

文章来源:https://blog.csdn.net/zuodingquan666/article/details/135357333
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。