本文主要是介绍Flume之使用Loadbalancing Sink Processor实现sink负载均衡,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
- Load balancing Sink Processor,顾名思义,即能够对Sink组中的每个Sink实现负载均衡,默认采用的是轮询round_robin的方式,还可以使用随机方式random,或者用户自己实现AbstractSinkSelector抽象类定义自己的Sink Selector类,并提供FQCN(Full Qualified Class Name)全类名来进行配置,并且Load balancing Sink Processor还提供了指数退避backoff,即当某个Sink挂掉时,将会将其加入到黑名单,一定时间内不再访问此Sink,退避时间呈指数增长并默认最大值为30000ms,可以手动设置
使用示例
1)flume1.properties
# flume1:此配置用于监控某个端口将其追加内容输出到flume2和flume3中
# 并将两个Sink组成一个sink group,并将Sink Processor设置成load_balance类型
# a1:Netcat Source-> Memory Channel-> Load balancing Sink Processor-> Avro Sink# Agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1 k2# Sink groups
a1.sinkgroups = g1
# 设置sink group中的sinks
a1.sinkgroups.g1.sinks = k1 k2
# 配置Load balancing Sink Processor(只有sink group才可以使用sink processor)
a1.sinkgroups.g1.processor.type = load_balance
# 设置开启指数避让
a1.sinkgroups.g1.processor.backoff = true
# 设置Processor的selector为轮询round_robin
a1.sinkgroups.g1.processor.selector = round_robin
# 设置最大避让时间(ms)
a1.sinkgroups.g1.processor.maxTimeOut = 10000# Sources
# 配置a1.sources.r1的各项属性参数,类型/绑定主机ip/端口号
a1.sources.r1.type = netcat
a1.sources.r1.bind = hadoop101
a1.sources.r1.port = 44444# Channels
# 配置a1.channerls.c1的各项属性参数,缓存方式/最多缓存的Event个数/单次传输的Event个数
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100# Sinks
# sinks.k1
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop102
a1.sinks.k1.port = 4141
# sinks.k2
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop103
a1.sinks.k2.port = 4141# Bind
# 注意:source可以绑定多个channel,但是sink/sink group只能绑定单个channel
# r1->c1->g1
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1
2)flume2.properties
# flume2:此配置用于将来自指定Avro端口的数据输出到控制台
# a2:Avro Source->Memory Channel->Logger Sink# Agent
a2.sources = r1
a2.channels = c1
a2.sinks = k1# Sources
# a2.sources.r1
a2.sources.r1.type = avro
# 设置监听本地IP
a2.sources.r1.bind = 0.0.0.0
# 设置监听端口号
a2.sources.r1.port = 4141# Channels
# a2.channels.c1
# 使用内存作为缓存/最多缓存的Event个数/单次传输的Event个数
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100# Sinks
# 运行时设置参数 -Dflume.root.logger=INFO,console 即输出到控制台实时显示
a2.sinks.k1.type = logger
# 设置Event的Body中写入log的最大字节数(默认值为16)
a2.sinks.k1.maxBytesToLog = 256# Bind
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1
3)flume3.properties
# flume3:此配置用于将来自指定Avro端口的数据输出到控制台
# a3:Avro Source->Memory Channel->Logger Sink# Agent
a3.sources = r1
a3.channels = c1
a3.sinks = k1# Sources
# a3.sources.r1
a3.sources.r1.type = avro
# 设置监听本地IP
a3.sources.r1.bind = 0.0.0.0
# 设置监听端口号
a3.sources.r1.port = 4141# Channels
# a3.channels.c1
# 使用内存作为缓存/最多缓存的Event个数/单次传输的Event个数
a3.channels.c1.type = memory
a3.channels.c1.capacity = 1000
a3.channels.c1.transactionCapacity = 100# Sinks
# 运行时设置参数 -Dflume.root.logger=INFO,console 即输出到控制台实时显示
a3.sinks.k1.type = logger
# 设置Event的Body中写入log的最大字节数(默认值为16)
a3.sinks.k1.maxBytesToLog = 256# Bind
a3.sources.r1.channels = c1
a3.sinks.k1.channel = c1
4)启动命令
Flume Agent a1至a3分别运行在主机hadoop101、hadoop102、hadoop103上
./bin/flume-ng agent -n a1 -c conf -f flume1.properties
./bin/flume-ng agent -n a2 -c conf -f flume2.properties -Dflume.root.logger=INFO,console
./bin/flume-ng agent -n a3 -c conf -f flume3.properties -Dflume.root.logger=INFO,console
5)实现功能
agent a1将指定端口的监听数据采用轮询的方式传输给a2和a3,并分别输出到各自的控制台
End~
这篇关于Flume之使用Loadbalancing Sink Processor实现sink负载均衡的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!