二百一十五、Flume——Flume拓扑结构之复制和多路复用的开发案例(亲测,附截图)

一、目的

对于Flume的复制和多路复用拓扑结构,进行一个小的开发测试

二、复制和多路复用拓扑结构

(一)结构含义

Flume 支持将事件流向一个或者多个目的地。

(二)结构特征

这种模式可以将相同数据复制到多个channel 中,或者将不同数据分发到不同的 channel 中,sink 可以选择传送到不同的目的地

三、需求案例

(一)案例需求

使用 Flume-1 监控文件变动,Flume-1 将变动内容传递给 Flume-2,Flume-2 负责存储到 HDFS。同时 Flume-1 将变动内容传递给 Flume-3,Flume-3 负责输出到 LocalFileSystem。

(二)需求分析

四、前期准备

(一)安装好Hadoop、Hive、Flume等工具

(二)查看Hive的日志在Linux系统中的文件路径

root@hurys23 conf\]# find / -name hive.log /home/log/hive312/hive.log ### (三)在HDFS中创建文件夹flume2,即Hive日志写入的HDFS文件 ### ![](https://file.jishuzhan.net/article/1734735507276959746/23486383c1e6c91315ccb0b36318d30c.webp) ### (四)在/opt/flume目录下创建 flume3 文件夹 \[root@hurys23 \~\]# cd /opt/flume/ \[root@hurys23 flume\]# mkdir flume3 \[root@hurys23 flume\]# ll 总用量 0 drwxr-xr-x 2 root root 6 12月 12 14:41 flume3 drwxr-xr-x 3 root root 102 12月 5 16:08 upload ![](https://file.jishuzhan.net/article/1734735507276959746/f3d568ce922d0937b00be6bb0e558523.webp) ## 五、创建flume的任务文件 ### (一)创建任务文件1 flume-file-flume.conf 配置1个接收日志文件的source和两个channel、两个sink,分别输送给 flume-flume-hdfs 和 flume-flume-dir。 \[root@hurys23 conf\]# vi flume-file-flume.conf # Name the components on this agent a1.sources = r1 a1.sinks = k1 k2 a1.channels = c1 c2 # 将数据流复制给所有 channel a1.sources.r1.selector.type = replicating # Describe/configure the source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /home/log/hive312/hive.log a1.sources.r1.shell = /bin/bash -c # Describe the sink # sink 端的 avro 是一个数据发送者 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 a1.channels.c2.type = memory a1.channels.c2.capacity = 1000 a1.channels.c2.transactionCapacity = 100 # Bind the source and sink to the channel a1.sources.r1.channels = c1 c2 a1.sinks.k1.channel = c1 a1.sinks.k2.channel = c2 ![](https://file.jishuzhan.net/article/1734735507276959746/dcc4df9c81fb7a7a31745d4db84d64f7.webp) 注意: 1、配置文件中的各项参数需要调式,这里只是为了演示,实现目的、打通路径即可!实际在项目中操作时需要调试参数。 2、a1.sources.r1.command = tail -F /home/log/hive312/hive.log 为hive.log在Linux中的路径 3、a1.sinks.k1.hostname = hurys23 hurys23 为服务器名字 ### (二)创建任务文件2 flume-flume-hdfs.conf 配置上级 Flume 输出的 Source,输出是到 HDFS 的 Sink。 \[root@hurys23 conf\]# vi flume-flume-hdfs.conf # Name the components on this agent a2.sources = r1 a2.sinks = k1 a2.channels = c1 # Describe/configure the source # source 端的 avro 是一个数据接收服务 a2.sources.r1.type = avro a2.sources.r1.bind = hurys23 a2.sources.r1.port = 4141 # Describe the sink a2.sinks.k1.type = hdfs a2.sinks.k1.hdfs.path = hdfs://hurys23:8020/flume2/%Y%m%d/%H #上传文件的前缀 a2.sinks.k1.hdfs.filePrefix = flume2- #是否按照时间滚动文件夹 a2.sinks.k1.hdfs.round = true #多少时间单位创建一个新的文件夹 a2.sinks.k1.hdfs.roundValue = 1 #重新定义时间单位 a2.sinks.k1.hdfs.roundUnit = hour #是否使用本地时间戳 a2.sinks.k1.hdfs.useLocalTimeStamp = true #积攒多少个 Event 才 flush 到 HDFS 一次 a2.sinks.k1.hdfs.batchSize = 100 #设置文件类型,可支持压缩 a2.sinks.k1.hdfs.fileType = DataStream #多久生成一个新的文件 a2.sinks.k1.hdfs.rollInterval = 30 #设置每个文件的滚动大小大概是 128M a2.sinks.k1.hdfs.rollSize = 134217700 #文件的滚动与 Event 数量无关 a2.sinks.k1.hdfs.rollCount = 0 # 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/1734735507276959746/aa46854c5aa8d37c492925180d711c7b.webp) 注意: 1、a2.sinks.k1.hdfs.path = hdfs://hurys23:8020/flume2/%Y%m%d/%H 为写入的HDFS文件路径 2、a2.sources.r1.bind = hurys23 hurys23 为服务器名字 ### (三)创建任务文件3 flume-flume-dir.conf 配置上级 Flume 输出的 Source,输出是到本地目录的 Sink。 \[root@hurys23 conf\]# vi flume-flume-dir.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 = file_roll a3.sinks.k1.sink.directory = /opt/flume/flume3 # 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/1734735507276959746/ae0b429a29be7f9e075434ef2c39a723.webp) 注意: 1、a3.sources.r1.bind = hurys23 hurys23 为服务器名字 2、a3.sinks.k1.sink.directory = /opt/flume/flume3 在Linux中的本地路径 3、/opt/flume/flume3 这个输出的本地目录必须是已经存在的目录,如果该目录不存在,并不会自动创建新的目录 ## 六、分别启动Flume任务文件 ### (一)首先启动 a3 flume-flume-dir.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a3 -f /usr/local/hurys/dc_env/flume/flume190/conf/flume-flume-dir.conf ![](https://file.jishuzhan.net/article/1734735507276959746/742c1b138653c8cc2da579931a79fe8f.webp) ### (二)其次启动 a2 flume-flume-hdfs.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a2 -f /usr/local/hurys/dc_env/flume/flume190/conf/flume-flume-hdfs.conf ![](https://file.jishuzhan.net/article/1734735507276959746/ca3464cd6c671d02135b68190428ae85.webp) ### (三)最后启动 a1 flume-file-flume.conf \[root@hurys23 flume190\]# bin/flume-ng agent -n a1 -f /usr/local/hurys/dc_env/flume/flume190/conf/flume-file-flume.conf ![](https://file.jishuzhan.net/article/1734735507276959746/8ff2da207e308c178f2b8ab8719c1ec3.webp) ## 七、Flume任务运行执行状况 ### (一)a1 a1任务运行截图 采集hive的log日志文件,发送给flume2、flume3 ![](https://file.jishuzhan.net/article/1734735507276959746/a0a0edf52a294a0c02f575d4c993b54e.webp) ### (二)a2 写入的HDFS文件状况 根据时间戳自动生成20231212文件夹、15文件夹及其flume2-文件 ![](https://file.jishuzhan.net/article/1734735507276959746/45104ad191a6a6ddc09fee6e25949036.webp) ![](https://file.jishuzhan.net/article/1734735507276959746/6b6fc04696769da14c35c21b3eac37f8.webp) ### (三)a3 写入的Linux本地文件状况 在Linux的 /opt/flume/flume3目录下自动生成相关文件 \[root@hurys23 flume3\]# ll 总用量 188 -rw-r--r-- 1 root root 0 12月 12 15:07 1702364829999-1 -rw-r--r-- 1 root root 1922 12月 12 15:07 1702364829999-2 -rw-r--r-- 1 root root 163250 12月 12 15:08 1702364829999-3 -rw-r--r-- 1 root root 23162 12月 12 15:08 1702364829999-4 -rw-r--r-- 1 root root 0 12月 12 15:09 1702364829999-5 ![](https://file.jishuzhan.net/article/1734735507276959746/fceb2a26e4edcfbbf78c02b436302a92.webp) Flume复制和多路复用拓扑结构的开发案例测试成功,简单来看,a1是source,a2、a3是sink 这种结构其实也挺常见的,就先到这里,Flume玩法还真挺多的!

相关推荐
Johny_Zhao2 分钟前
Ubuntu安装部署Zabbix网络监控平台和设备配置添加
linux·网络·mysql·网络安全·信息安全·云计算·apache·zabbix·shell·yum源·系统运维·itsm
chennalC#c.h.JA Ptho27 分钟前
kubuntu系统详解
linux·数据库·经验分享·postgresql·系统安全
熙曦Sakura32 分钟前
【Linux网络】HTTPS
linux·网络·https
铁锚34 分钟前
一个WordPress连续登录失败的问题排查
java·linux·服务器·nginx·tomcat
程序视点1 小时前
Linux中find命令用法核心要点提炼
linux·linux命令·linux指令·linux的find命令
cwywsx1 小时前
Linux:进程控制2
linux·运维·算法
熙曦Sakura1 小时前
【Linux网络】 HTTP cookie与session
linux·网络·http
南棱笑笑生1 小时前
20250512给NanoPi NEO core开发板在Ubuntu core20.04系统下重新编译boot.img
linux·运维·ubuntu
Ha-gd2 小时前
Linux基础开发工具一(yum/apt ,vim)
linux·服务器
charlie1145141912 小时前
内核深入学习3——分析ARM32和ARM64体系架构下的Linux内存区域示意图与页表的建立流程
linux·学习·架构·内存管理