Flume多路复用及故障转移案例

复制和多路复用:
  • 使用Flume-1监控文件变动
  • Flume-1将变动内容传递给Flume-2
  • Flume-2负责存储到HDFS
  • 同时Flume-1将变动内容传递给Flume-3
  • Flume-3负责输出到Local FileSystem
Channel1
Memory Channel
Channel12
Memory Channel
exec Source
Avro Sink1
Avro Source
HDFS Sink
Avro Sink2
Avro Source
File_roll Sink

vim flume1.conf

#Name															
a1.sources = r1
a1.channels = c1 c2
a1.sinks = k1 k2
# Describe/configure the source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /data/txt/files/1.txt
a1.sources.r1.positionFile = /opt/modules/apache-flume-1.6.0-cdh5.15.1-    bin/position/position.json
a1.sources.r1.selector.type = replicating

# Use a channel which buffers events in memory
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

# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = centos7
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = centos7
a1.sinks.k2.port = 4142

# Bind the source and sink to the channel
a1.sources.r1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2

vim flume2.conf

#Name
a2.sources = r1
a2.channels = c1
a2.sinks = k1

# Describe/configure the source
a2.sources.r1.type = avro
a2.sources.r1.bind = centos7
a2.sources.r1.port = 4141

# Use a channel which buffers events in memory
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

# Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = /flume/group1/%Y%m%d/%H
a2.sinks.k1.hdfs.filePrefix = logs-
a2.sinks.k1.hdfs.round = true
a2.sinks.k1.hdfs.roundValue = 1
a2.sinks.k1.hdfs.roundUnit = hour
a2.sinks.k1.hdfs.useLocalTimeStamp = true
a2.sinks.k1.hdfs.batchSize = 1000
a2.sinks.k1.hdfs.rollInterval = 30
a2.sinks.k1.hdfs.fileType = DataStream
a2.sinks.k1.hdfs.rollSize = 134217700
a2.sinks.k1.hdfs.rollCount = 0

# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1

vim flume3.conf

#Name
a3.sources = r1
a3.channels = c1
a3.sinks = k1

# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = centos7
a3.sources.r1.port = 4142

# Use a channel which buffers events in memory
a3.channels.c1.type = memory
a3.channels.c1.capacity = 1000
a3.channels.c1.transactionCapacity = 100
										
# Describe the sink
a3.sinks.k1.type = flie_roll
a3.sinks.k1.sink.directory = /data/txt/group1

# Bind the source and sink to the channel
a3.sources.r1.channels = c1
a3.sinks.k1.channel = c1

按顺序执行命令即可,亲测无误 哈哈哈 ^ ^

bin/flume-ng agent \
-c conf \
-f jobs/flume1.conf \
-n a1 \
-Dflume.root.logger=INFO,console

bin/flume-ng agent \
-c conf \
-f jobs/flume2.conf \
-n a2 \
-Dflume.root.logger=INFO,console

bin/flume-ng agent \
-c conf \
-f jobs/flume3.conf \
-n a3 \
-Dflume.root.logger=INFO,console
故障转移和负载均衡:

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

flume1.conf

#Name
a1.sources = r1
a1.channels = c1
a1.sinks = k1 k2
a1.sinkgroups = g1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44445

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = centos7
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = centos7
a1.sinks.k2.port = 4142
#sink group
a1.sinkgroups.g1.sinks = k1 k2
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1

vim flume2.conf

#Name
a2.sources = r1
a2.channels = c1
a2.sinks = k1

# Describe/configure the source
a2.sources.r1.type = avro
a2.sources.r1.bind = centos7
a2.sources.r1.port = 4141

# Use a channel which buffers events in memory
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

# Describe the sink
a2.sinks.k1.type = logger

# Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1

flume3.conf

#Name
a3.sources = r1
a3.channels = c1
a3.sinks = k1

# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = centos7
a3.sources.r1.port = 4142

# Use a channel which buffers events in memory
a3.channels.c1.type = memory
a3.channels.c1.capacity = 1000
a3.channels.c1.transactionCapacity = 100
										
# Describe the sink
a3.sinks.k1.type = logger

# Bind the source and sink to the channel
a3.sources.r1.channels = c1
a3.sinks.k1.channel = c1

netstat -apn | grep 44444 可查看端口是被谁占用了

负载均衡

# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = centos7
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = centos7
a1.sinks.k2.port = 4142
#sink group
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processor.selector = random   //随机发送数据
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值