复制和多路复用:
- 使用Flume-1监控文件变动
- Flume-1将变动内容传递给Flume-2
- Flume-2负责存储到HDFS
- 同时Flume-1将变动内容传递给Flume-3
- Flume-3负责输出到Local FileSystem
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 //随机发送数据