一、实现功能
flume监控一个日志文件,并将数据传送给kafka,然后另外一个flume从kafka获得数据。
二、实现步骤
1.环境
flume1.6.0
kafka_2.10-0.8.2.1
zookeeper3.4.5
2.flume监控日志,并且传送给kafka的配置文件test1_1.6.conf
【参考:http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.7.0/FlumeUserGuide.html】
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -f /opt/datas/access.log
a1.sources.r1.channels = c1
# 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 = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.topic = hadoop2
a1.sinks.k1.brokerList = hadoop:9092,hadoop:9093
a1.sinks.k1.requiredAcks = 1
a1.sinks.k1.batchSize = 20
a1.sinks.k1.channel = c1
3.flume从kafka获得消费数据配置文件test2_1.6.conf
【参考:http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.7.0/FlumeUserGuide.html】
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1
#Configure of Flume Agent Source
a2.sources.r1.type = org.apache.flume.source.kafka.KafkaSource
a2.sources.r1.channels = c1
a2.sources.r1.topic= hadoop1
a2.sources.r1.groupId = flume
a2.sources.r1.zookeeperConnect = localhost:2181/kafka08
#Configure of Flume Agent Source
a2.channels.c1.type = memory
# Configure of Flume Agent Sink=>Kafka Sink
a2.sinks.k1.type=logger
a2.sinks.k1.channel=c1
4.kafka创建topic:hadoop1
bin/kafka-topics.sh --create --topic hadoop1 --zookeeper hadoop:2181/kafka08 --partitions 5 --replication-factor 2
三、测试
1.启动zk:
cd /opt/modules/zookeeper-3.4.5
bin/zkServer.sh start
2.启动kafka
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/server1.properties
3.启动监控日志并传递kafka的flume服务test1_1.6.conf
bin/flume-ng agent --name a1 --conf ./conf/ --conf-file ./conf/test1_1.6.conf -Dflume.root.logger=INFO,console
4.启动从kafka获得信息的flume服务test2_1.6.conf
bin/flume-ng agent --name a2 --conf ./conf/ --conf-file ./conf/test2_1.6.conf -Dflume.root.logger=INFO,console
5.启动kafka消费者
bin/kafka-console-consumer.sh --topic hadoop1 --zookeeper hadoop:2181/kafka08
6.输入数据到检测文件
echo "liuming gerry tom" >> /opt/datas/access.log