Flume 入门案例
-
案例需求:使用 Flume 监听一个端口,收集该端口数据,并打印到控制台。
- 安装 netcat 工具
sudo yum install -y nc
- 判断 44444 端口是否被占用
sudo netstat -nlp | grep 44444
-
在 flume 目录下创建 job 文件夹并进入 job 文件夹。
mkdir 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.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
先按下ESC键,按:键,输入wq,保存退出
-
先开启 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:表示配置文件存储在 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。想要了解更多知识可去官网查询,配置文件来源于官方手册 http://flume.apache.org/FlumeUserGuide.html - 需要再开一个终端,使用 netcat 工具向本机的 44444 端口发送内容
nc localhost 44444
发送hello,
另一边接收消息
-
这样环境搭建测试完成
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通