03 Flume入门案例之监控端口数据

案例需求:

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

需求分析

 实现步骤:

安装netcat

yum install -y nc

查看44444端口有没有被占用

netstat -nlp | grep 44444

 

 在 flume 目录下创建 job 文件夹并进入 job 文件夹

mkdir -p job && cd job

在 job 文件夹下创建 Flume Agent 配置文件 flume-netcat-logger.conf,名字可以随意起

vim flume-netcat-logger.conf

 在 flume-netcat-logger.conf 文件中添加如下内容:

# Name the components on this agent
# a1为Agent事件的名称,在一台机器上Agent名称必须唯一,r1,k1,c1分别为三个组件起的名字,可以自定义
# 一个Agent可以有多个source,sink,channel
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
# 定义sink的数据类型
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
# 定义通道的类型,数据的容量(总容量为1000个event),事务的容量(一次传输100个event)
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
# 配置source,sink归属于哪条通道,一个source可以绑定多个channel,一个sink只能绑定一个channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

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

 先开启 flume 监听端口

# 第一种写法
bin/flume-ng agent -c conf/ -n a1 -f job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console

# 第二种写法
bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-netcat-logger.conf - Dflume.root.logger=INFO,console

参数说明:

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

--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

 

 另起一个窗口,使用 netcat 工具向本机的 44444 端口发送内容

nc localhost 44444

发送数据

 

 flume端监听数据

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值