kafka(十二):Kafka和flume整合

38 篇文章 2 订阅
25 篇文章 2 订阅

一、实现功能

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

(测试成功!)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值