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

本文主要是介绍二百一十五、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文件

(四)在/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

五、创建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

注意

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

注意:

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

注意:

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

(二)其次启动   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

(三)最后启动   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

七、Flume任务运行执行状况

(一)a1  a1任务运行截图

采集hive的log日志文件,发送给flume2、flume3

(二)a2   写入的HDFS文件状况

根据时间戳自动生成20231212文件夹、15文件夹及其flume2-文件

(三)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

Flume复制和多路复用拓扑结构的开发案例测试成功,简单来看,a1是source,a2、a3是sink

这种结构其实也挺常见的,就先到这里,Flume玩法还真挺多的!

这篇关于二百一十五、Flume——Flume拓扑结构之复制和多路复用的开发案例(亲测,附截图)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/498502

相关文章

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

使用Java实现通用树形结构构建工具类

《使用Java实现通用树形结构构建工具类》这篇文章主要为大家详细介绍了如何使用Java实现通用树形结构构建工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录完整代码一、设计思想与核心功能二、核心实现原理1. 数据结构准备阶段2. 循环依赖检测算法3. 树形结构构建4. 搜索子

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

利用Go语言开发文件操作工具轻松处理所有文件

《利用Go语言开发文件操作工具轻松处理所有文件》在后端开发中,文件操作是一个非常常见但又容易出错的场景,本文小编要向大家介绍一个强大的Go语言文件操作工具库,它能帮你轻松处理各种文件操作场景... 目录为什么需要这个工具?核心功能详解1. 文件/目录存javascript在性检查2. 批量创建目录3. 文件

基于Python开发批量提取Excel图片的小工具

《基于Python开发批量提取Excel图片的小工具》这篇文章主要为大家详细介绍了如何使用Python中的openpyxl库开发一个小工具,可以实现批量提取Excel图片,有需要的小伙伴可以参考一下... 目前有一个需求,就是批量读取当前目录下所有文件夹里的Excel文件,去获取出Excel文件中的图片,并