二百一十六、Flume——Flume拓扑结构之负载均衡和故障转移的开发案例(亲测,附截图)

一、目的

对于Flume的负载均衡和故障转移拓扑结构,进行一个开发测试

二、负载均衡和故障转移

(一)结构含义

Flume支持使用将多个sink逻辑上分到一个sink组

(二)结构特征

sink组配合不同的SinkProcessor可以实现负载均衡和错误恢复的功能

三、需求案例

(一)案例需求

使用 Flume1 监控一个端口,其sink组中的sink分别对接 Flume2 和 Flume3,采用FailoverSinkProcessor,实现故障转移的功能。

(二)需求分析

四、前期准备

(一)安装好Flume工具

(二)在Flume中创建测试任务的文件夹group2

root@hurys23 conf\]# mkdir group2 \[root@hurys23 conf\]# cd ./group2/ \[root@hurys23 group2\]# pwd /usr/local/hurys/dc_env/flume/flume190/conf/group2 ## 五、在group2中创建flume的任务文件 ### (一)创建任务文件 a1 flume-netcat-flume.conf 配置 1 个 netcat source 和 1 个 channel、1 个 sink group(2 个 sink),分别输送给flume-flume-console1 和 flume-flume-console2。 \[root@hurys23 group2\]# vi flume-netcat-flume.conf # Name the components on this agent a1.sources = r1 a1.channels = c1 a1.sinkgroups = g1 a1.sinks = k1 k2 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 a1.sinkgroups.g1.processor.type = failover a1.sinkgroups.g1.processor.priority.k1 = 5 a1.sinkgroups.g1.processor.priority.k2 = 10 a1.sinkgroups.g1.processor.maxpenalty = 10000 # Describe the sink a1.sinks.k1.type = avro a1.sinks.k1.hostname = hurys23 a1.sinks.k1.port = 4141 a1.sinks.k2.type = avro a1.sinks.k2.hostname = hurys23 a1.sinks.k2.port = 4142 # Describe the channel 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.sinkgroups.g1.sinks = k1 k2 a1.sinks.k1.channel = c1 a1.sinks.k2.channel = c1 ![](https://file.jishuzhan.net/article/1734739874533085185/1e39c9f7ea1085ec2c2a813b608b4880.webp) 注意: 1、配置文件中的各项参数需要调式,这里只是为了演示,实现目的、打通路径即可!实际在项目中操作时需要调试参数。 2、a1.sinks.k1.hostname = hurys23 hurys23 为服务器名字 ### (二)创建任务文件 a2 flume-flume-console1.conf 配置上级 Flume 输出的 Source,输出是到本地控制台。 \[root@hurys23 group2\]# vi flume-flume-console1.conf # Name the components on this agent a2.sources = r1 a2.sinks = k1 a2.channels = c1 # Describe/configure the source a2.sources.r1.type = avro a2.sources.r1.bind = hurys23 a2.sources.r1.port = 4141 # Describe the sink a2.sinks.k1.type = logger # Describe the channel a2.channels.c1.type = memory a2.channels.c1.capacity = 1000 a2.channels.c1.transactionCapacity = 100 # Bind the source and sink to the channel a2.sources.r1.channels = c1 a2.sinks.k1.channel = c1 ### ![](https://file.jishuzhan.net/article/1734739874533085185/6608dbde876158d3dfe212ab5c2aa74d.webp) (三)创建任务文件 a3 flume-flume-console2.conf 配置上级 Flume 输出的 Source,输出是到本地控制台。 \[root@hurys23 group2\]# vi flume-flume-console2.conf # Name the components on this agent a3.sources = r1 a3.sinks = k1 a3.channels = c2 # Describe/configure the source a3.sources.r1.type = avro a3.sources.r1.bind = hurys23 a3.sources.r1.port = 4142 # Describe the sink a3.sinks.k1.type = logger # Describe the channel a3.channels.c2.type = memory a3.channels.c2.capacity = 1000 a3.channels.c2.transactionCapacity = 100 # Bind the source and sink to the channel a3.sources.r1.channels = c2 a3.sinks.k1.channel = c2 ![](https://file.jishuzhan.net/article/1734739874533085185/c2e42340eaa3118c4262d190c3a9cbda.webp) ## 六、分别启动Flume任务文件 ### (一)首先启动 a3 flume-flume-console2.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a3 -f /usr/local/hurys/dc_env/flume/flume190/conf/group2/flume-flume-console2.conf ![](https://file.jishuzhan.net/article/1734739874533085185/2d7108ee10a66003a7ae4c515bdc15b6.webp) ### (二)其次启动 a2 flume-flume-console1.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a2 -f /usr/local/hurys/dc_env/flume/flume190/conf/group2/flume-flume-console1.conf ![](https://file.jishuzhan.net/article/1734739874533085185/bc61a521bed92958751d304db7da3ef1.webp) ### (三)最后启动 a1 flume-netcat-flume.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a1 -f /usr/local/hurys/dc_env/flume/flume190/conf/group2/flume-netcat-flume.conf ![](https://file.jishuzhan.net/article/1734739874533085185/a3a759b53e2c9250c1a0084de4494893.webp) ## 七、使用 netcat 工具向本机的 44444 端口发送内容 \[root@hurys23 \~\]# nc localhost 44444 hello world OK hello java OK hello hadoop OK hello flume OK ![](https://file.jishuzhan.net/article/1734739874533085185/d50c70d04a6526d1e7aa66f20b568e37.webp) ## 八、Flume任务运行执行状况 ### (一)a1 a1任务运行截图 ![](https://file.jishuzhan.net/article/1734739874533085185/ac7eea700bb35eb27579ed42bbdb000b.webp) ### (二)a2 a2任务运行截图 ![](https://file.jishuzhan.net/article/1734739874533085185/e35f264ed037179db189d5cb3c723d7d.webp) ### (三)a3 a3任务运行截图 2023-12-12 17:29:38,391 INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 hello world } 2023-12-12 17:29:43,331 INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 6A 61 76 61 hello java } 2023-12-12 17:29:49,027 INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 68 61 64 6F 6F 70 hello hadoop } 2023-12-12 17:29:53,028 INFO sink.LoggerSink: Event: { headers:{} body: 68 65 6C 6C 6F 20 66 6C 75 6D 65 hello flume } ![](https://file.jishuzhan.net/article/1734739874533085185/d0ab254c02b42d834c7c7397b5c5f740.webp) Flume负载均衡和故障转移拓扑结构的测试成功,当然这个案例比较简单。 Flume玩法继续研究中!

相关推荐
三坛海会大神55527 分钟前
LVS与Keepalived详解(一)负载均衡集群介绍
运维·负载均衡·lvs
m0_464608264 小时前
Nginx反向代理与负载均衡部署
运维·nginx·负载均衡
阿拉斯加大闸蟹15 小时前
基于RDMA 通信的可负载均衡高性能服务架构
运维·架构·负载均衡
请提交用户昵称17 小时前
大数据各组件flume,datax,presto,DolphinScheduler,findBI在大数据数仓架构中的作用和功能。
大数据·flume·datax·dolphin·presto·findbi·大数据组件
✎﹏赤子·墨筱晗♪1 天前
基于Nginx实现反向代理、负载均衡与动静分离完整部署指南
运维·nginx·负载均衡
linweidong2 天前
负载均衡的LVS三种模式:NAT、TUN、DR场景对比与实践指南
负载均衡·lvs·dr模式·ip隧道·运维面经·k8s面试·docker面试
乐大师2 天前
腾讯云负载均衡增加访问策略后访问失败
云计算·负载均衡·腾讯云
2301_803554522 天前
正向代理,反向代理,负载均衡还有nginx
java·nginx·负载均衡
fuyongliang1233 天前
nginx反向代理,负载均衡,tomcat的数据流向图篇解析
nginx·tomcat·负载均衡
✎﹏赤子·墨筱晗♪3 天前
从反向代理到负载均衡:Nginx + Tomcat 构建高可用Web服务架构
nginx·tomcat·负载均衡