栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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端监听数据

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/307359.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号