Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合

简介: Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合

1、Flume进阶

1.1 Flume事务


bf2f7545662b4f97acfc0422257b9b3c.png

1.2 Flume Agent内存原理


c701f6ddf7ac45e4ae392e6b9ede4dff.png

1、ChannelSelector

ChannelSelector的作用就是选出Event将要被发往哪个Channel。其共有两种类型,分别是Replicating(复制)和Multiplexing(多路复用)。

ReplicatingSelector会将同一个Event发往所有的Channel,Multiplexing会根据相应的原则,将不同的Event发往不同的Channel。

2、SinkProcessor

SinkProcessor共有三种类型,分别是DefaultSinkProcessor、LoadBalancingProcessor和FailoverSinkProcessor。

DefaultSinkProcessor对应的是单个的Sink,LoadBalancingSinkProcessor和FailoverProcessor对应的是Sink,Group,LoadBalancingSinkProcessor可以实现负载均衡的功能,FailoverSinkProcessor可以错误恢复功能。

1.3 拓扑结构

1.3.1 简单串联


2d592f888d8948a2830a6a8ad1294259.png

这种模式是将多个 flume 顺序连接起来了,从最初的 source 开始到最终 sink 传送的目的存储系统。此模式不建议桥接过多的 flume 数量, flume 数量过多不仅会影响传输速率,而且一旦传输过程中某个节点 flume 宕机,会影响整个传输系统。

1.3.2 复制和多路复用


d275e460476048ddaf7c0084443c46d3.png

Flume 支持将事件流向一个或者多个目的地。这种模式可以将相同数据复制到多个channel 中,或者将不同数据分发到不同的 channel 中,sink 可以选择传送到不同的目的地。

1.3.3 负载均衡和故障转移


e1f63a1aa96448bba8d8f8d06b288b5e.png

Flume支持使用将多个sink逻辑上分到一个sink组,sink组配合不同的SinkProcessor可以实现负载均衡和错误恢复的功能。

1.3.4 聚合


49561aede6d444148af13d93226a8776.png

这种模式是我们最常见的,也非常实用,日常 web 应用通常分布在上百个服务器,大者甚至上千个、上万个服务器。产生的日志,处理起来也非常麻烦。用 flume 的这种组合方式能很好的解决这一问题,每台服务器部署一个 flume 采集日志,传送到一个集中收集日志的flume,再由此 flume 上传到 hdfs、hive、hbase 等,进行日志分析。

1.4 案例实现

前提说明:在Flume之间传输数据要用avro,并且Source用的是avro的FlumeAgent是服务端,在开启时要先开启服务端!!!!

1.4.1 复制和多路复用

1、案例需求

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

2、需求分析


7e508cfcf0c14c019ad1136d7d09709c.png

3、实现步骤

(1)准备工作

在/opt/module/flume/job 目录下创建 group1 文件夹

在/opt/module/datas/目录下创建 flume3 文件夹

(2)创建 flume-file-flume.conf(group1文件夹下)

# 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 /opt/module/hive/logs/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
# sink 端的 avro 是一个数据发送者
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop102
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop102
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

3)创建 flume-flume-hdfs.conf(group1文件夹下)

作用:配置上级 Flume 输出的 Source,输出是到 HDFS 的 Sink。

# 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 = hadoop102
a2.sources.r1.port = 4141
# Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://hadoop102:9820/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

(4)创建 flume-flume-dir.conf(group1文件夹下)

作用:配置上级 Flume 输出的 Source,输出是到本地目录的 Sink。

# 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 = hadoop102
a3.sources.r1.port = 4142
# Describe the sink
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /opt/module/data/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

(5)执行配置文件

 bin/flume-ng agent --conf conf/ --name a3 --conf-file job/group1/flume-flume-dir.conf
 bin/flume-ng agent --conf conf/ --name a2 --conf-file job/group1/flume-flume-hdfs.conf
 bin/flume-ng agent --conf conf/ --name a1 --conf-file job/group1/flume-file-flume.conf

(6)启动hadoop和Hive

start-dfs.sh
start-yarn.sh
 bin/hive

(7)检查HDFS上数据


2ad021631efb43caabb42c46eec4b48d.png

(8)检查/opt/module/datas/flume3 目录中数据

1.4.2 负载均衡和故障转移

1、案例需求

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

2、需求分析

bc8fbf1862e7474c819ef6beae2f3f54.png




相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
5月前
|
Kubernetes 负载均衡 应用服务中间件
k8s学习-CKA真题-七层负载均衡Ingress
k8s学习-CKA真题-七层负载均衡Ingress
54 0
|
5月前
|
负载均衡 算法 Nacos
【Ribbon实现客户端负载均衡和故障转移】—— 每天一点小知识
【Ribbon实现客户端负载均衡和故障转移】—— 每天一点小知识
156 0
|
9月前
|
存储 Java 分布式数据库
Flume学习---3、自定义Interceptor、自定义Source、自定义Sink
Flume学习---3、自定义Interceptor、自定义Source、自定义Sink
|
9月前
|
监控 负载均衡
Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合(二)
Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合(二)
|
9月前
|
SQL 存储 分布式计算
Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合(一)
Flume学习---2、Flume进阶(事务)、负载均衡、故障转移、聚合(一)
|
25天前
|
存储 消息中间件 监控
【Flume】Flume在大数据分析领域的应用
【4月更文挑战第4天】【Flume】Flume在大数据分析领域的应用
|
8月前
|
SQL 分布式计算 监控
大数据Flume快速入门
大数据Flume快速入门
57 0
|
8月前
|
SQL 存储 监控
大数据Flume企业开发实战
大数据Flume企业开发实战
37 0
|
7月前
|
数据采集 消息中间件 监控
大数据组件-Flume集群环境搭建
大数据组件-Flume集群环境搭建
116 0
|
7月前
|
Oracle 大数据 关系型数据库
大数据组件-Flume集群环境的启动与验证
大数据组件-Flume集群环境的启动与验证
94 0