flume配置与启动
官方文档
配置flume-conf.properties.template
agent.sources = seqGenSrc
agent.channels = memoryChannel
agent.sinks = loggerSink
# For each one of the sources, the type is defined
agent.sources.seqGenSrc.type = seq
# The channel can be defined as follows.
agent.sources.seqGenSrc.channels = memoryChannel
# Each sink's type must be defined
agent.sinks.loggerSink.type = logger
#Specify the channel the sink should use
agent.sinks.loggerSink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100
启动flume
bin/flume-ng agent -n agent -c conf -f conf/flume-conf.properties.template -Dflume.root.logger=INFO,console
flume集群
示意图
设计
服务器 | 角色 |
cdh2 | 监听文件变化 |
cdh3 | 监听文件变化 |
cdh1 | 显示cdh1和cdh2的变化 |
配置文件
flume-conf-1(cdh2、cdh3)
agent.sources = execSource
agent.channels = memoryChannel
agent.sinks = avroSink
# For each one of the sources, the type is defined
agent.sources.execSource.type = exec
agent.sources.execSource.command = tail -F /root/data/flume/test.log
agent.sources.execSource.channels = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100
# Each sink's type must be defined
agent.sinks.avroSink.type = avro
agent.sinks.avroSink.channel = memoryChannel
agent.sinks.avroSink.hostname = cdh1
agent.sinks.avroSink.port = 1234
flume-conf-2(cdh1)
agent.sources = avroSource
agent.channels = memoryChannel
agent.sinks = loggerSink
# For each one of the sources, the type is defined
agent.sources.avroSource.type = avro
agent.sources.avroSource.channels = memoryChannel
agent.sources.avroSource.bind = 0.0.0.0
agent.sources.avroSource.port = 1234
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100
# Each sink's type must be defined
agent.sinks.loggerSink.type = logger
agent.sinks.loggerSink.channel = memoryChannel
分发flume并创立软连接
/root/tools/deploy.sh /root/app/apache-flume-1.7.0-bin /root/app/ slave
集群启动
cdh2、cdh3
bin/flume-ng agent -n agent -c conf -f conf/flume-conf-1.properties -Dflume.root.logger=INFO,console
cdh1
bin/flume-ng agent -n agent -c conf -f conf/flume-conf-2.properties -Dflume.root.logger=INFO,console
测试
cdh2
[root@cdh2 flume]# echo "cdh2" >>test.log
[root@cdh2 flume]# echo "cdh2" >>test.log
[root@cdh2 flume]# echo "cdh2" >>test.log
cdh3
[root@cdh3 flume]# echo "cdh3" >>test.log
[root@cdh3 flume]# echo "cdh3" >>test.log
[root@cdh3 flume]# echo "cdh3" >>test.log
cdh1效果
flume与kafka集成
设计
服务器 | 服务 | Source | sink |
cdh2 | flume | 监听文件变化 tail-f | 收集的数据落库到cdh1的flume |
cdh3 | flume | 监听文件变化 tail-f | 收集的数据落库到cdh1的flume |
cdh1 | flume | 监听cdh2、cdh3发送的数据 | 收集的数据落库到kafka |
配置
flume-conf-1(cdh2、cdh3)
agent.sources = execSource
agent.channels = memoryChannel
agent.sinks = avroSink
# For each one of the sources, the type is defined
agent.sources.execSource.type = exec
agent.sources.execSource.command = tail -F /root/data/flume/test.log
agent.sources.execSource.channels = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100
# Each sink's type must be defined
agent.sinks.avroSink.type = avro
agent.sinks.avroSink.channel = memoryChannel
agent.sinks.avroSink.hostname = cdh1
agent.sinks.avroSink.port = 1234
flume-conf-3(cdh1)
agent.sources = avroSource
agent.channels = memoryChannel
agent.sinks = kafkaSink
# For each one of the sources, the type is defined
agent.sources.avroSource.type = avro
agent.sources.avroSource.channels = memoryChannel
agent.sources.avroSource.bind = 0.0.0.0
agent.sources.avroSource.port = 1234
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
agent.channels.memoryChannel.capacity = 100
# Each sink's type must be defined
agent.sinks.kafkaSink.type = org.apache.flume.sink.kafka.KafkaSink
agent.sinks.kafkaSink.kafka.topic = test
agent.sinks.kafkaSink.kafka.bootstrap.servers = cdh1:9092,cdh2:9092,cdh3:9092
agent.sinks.kafkaSink.channel = memoryChannel
cdh2、cdh3
bin/flume-ng agent -n agent -c conf -f conf/flume-conf-1.properties -Dflume.root.logger=INFO,console
cdh1
bin/flume-ng agent -n agent -c conf -f conf/flume-conf-3.properties -Dflume.root.logger=INFO,console
测试
cdh2