|NO.Z.00042|——————————|BigDataEnd|——|Hadoop&Flume.V05|——|Flume.v05|Flume.v1.9案例.v03|

一、入门案例
### --- 中文flume帮助文档:https://flume.liyifeng.org/

~~~     # 业务需求:
~~~     监听本机 8888 端口,Flume将监听的数据实时显示在控制台
### --- 需求分析:

~~~     使用 telnet 工具可以向 8888 端口发送数据
~~~     监听端口数据,选择 netcat source
~~~     channel 选择 memory
~~~     数据实时显示,选择 logger sink
二、实现步骤:
### --- 安装 telnet 工具

[root@linux123 ~]# yum install -y telnet 
### --- 检查 8888 端口是否被占用。如果该端口被占用,可以选择使用其他端口完成任务

lsof -i:8888
### --- 创建 Flume Agent 配置文件。 flume-netcat-logger.conf
~~~     Memory Channel 是使用内存缓冲Event的Channel实现。
~~~     速度比较快速,容量会受到 jvm 内存大小的限制,可靠性不够高。
~~~     适用于允许丢失数据,但对性能要求较高的日志采集业务。

[root@linux123 ~]# vim /opt/yanqi/servers/flume-1.9.0/conf/flume-netcat-logger.conf
# a1是agent的名称。source、channel、sink的名称分别为:r1 c1 k1
a1.sources = r1
a1.channels = c1
a1.sinks = k1

# source
a1.sources.r1.type = netcat
a1.sources.r1.bind = linux123
a1.sources.r1.port = 8888

# channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 100

# sink
a1.sinks.k1.type = logger

# source、channel、sink之间的关系
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
### --- 启动Flume Agent

[root@linux123 ~]# $FLUME_HOME/bin/flume-ng agent --name a1 \
--conf-file $FLUME_HOME/conf/flume-netcat-logger.conf \
-Dflume.root.logger=INFO,console
~~~     name。定义agent的名字,要与参数文件一致
~~~     conf-file。指定参数文件位置
~~~     -D表示flume运行时动态修改 flume.root.logger 参数属性值,
~~~     并将控制台日志打印级别设置为INFO级别。日志级别包括:log、info、warn、error
### --- 使用 telnet 向本机的 8888 端口发送消息

[root@linux123 ~]# telnet linux123 8888
Trying 192.168.1.123...
Connected to linux123.
Escape character is '^]'.
hello world .
OK
are you ok?  
OK
### --- 在 Flume 监听页面查看数据接收情况

~~~     # flume输出参数
INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 20 2E 0D       hello world .. }
INFO sink.LoggerSink: Event: { headers:{} body: 61 72 65 20 79 6F 75 20 6F 6B 3F 0D             are you ok?. }

 
 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(16)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示