数据获取层之Flume快速入门(一) 入门案例

数据获取层之Flume快速入门(一) 入门案例

经验文章nimo972025-03-10 14:21:2612A+A-

监控端口数据官方案例

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

需求分析:


实现步骤:

1、安装 netcat 工具

sudo yum install -y nc

2、判断 33333 端口是否被占用

sudo netstat -tunlp | grep 33333

3、在 flume 目录下创建 job 文件夹并进入 job 文件夹,创建 Flume Agent 配置文件 flume-netcat-logger.conf

mkdir job
cd job/
vim flume-netcat-logger.conf

在 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 = 33333
# 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 -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。

5、使用 netcat 工具向本机的 33333 端口发送内容

nc localhost 33333

输入:

Hello world!

6、在 Flume 监听控制台观察接收日志打印数据情况

source.NetcatSource: Source starting
INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/127.0.0.1:33333]
INFO sink.LoggerSink: Event: { headers:{} body: 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D Hello world!}
点击这里复制本文地址 以上内容由nimo97整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

尼墨宝库 © All Rights Reserved.  蜀ICP备2024111239号-7