Flume简介与使用(三)——Kafka Sink消费数据之Kafka安装
2016-08-30 00:31
387 查看
前面已经介绍了如何利用Thrift Source生产数据,今天介绍如何用Kafka Sink消费数据。
其实之前已经在Flume配置文件里设置了用Kafka Sink消费数据
那么当Flume的channel收到数据的时候,会根据配置文件主动把数据event发送到Kafka的broker上,所以只要安装好Kafka就可以消费收据了。
> tar -xzf kafka_2.11-0.10.0.0.tgz
> cd kafka_2.11-0.10.0.0
> %Zookeeper_Home%/bin[b]/zkServer.sh start[/b]
在配置文件server.properties中把下面一句前面的注释去掉,然后启动Kafka服务器
[b] > #listeners=PLAINTEXT://:9092[/b]
[b] >[/b] bin/kafka-server-start.sh config/server.properties
接下来启动其他两个broker:
> cp config/server.properties config/server-1.properties
> cp config/server.properties config/server-2.properties
修改配置文件,broker.id不能重复
> bin/kafka-topics.sh --create --zookeeper 10.208.129.4:2181 --replication-factor 3 --partitions 1 --topic TRAFFIC_LOG
其实之前已经在Flume配置文件里设置了用Kafka Sink消费数据
agent1.sinks.kafkaSink.type = org.apache.flume.sink.kafka.KafkaSink agent1.sinks.kafkaSink.topic = TRAFFIC_LOG agent1.sinks.kafkaSink.brokerList = 10.208.129.3:9092,10.208.129.4:9092,10.208.129.5:9092 agent1.sinks.kafkaSink.metadata.broker.list = 10.208.129.3:9092,10.208.129.4:9092,10.208.129.5:9092 agent1.sinks.kafkaSink.producer.type=sync agent1.sinks.kafkaSink.serializer.class=kafka.serializer.DefaultEncoder agent1.sinks.kafkaSink.channel = memoryChannel
那么当Flume的channel收到数据的时候,会根据配置文件主动把数据event发送到Kafka的broker上,所以只要安装好Kafka就可以消费收据了。
Step 1: Download the code
下载安装包并解压> tar -xzf kafka_2.11-0.10.0.0.tgz
> cd kafka_2.11-0.10.0.0
Step 2: Start the server
Kafka是基于Zookeeperl来实现分布式协同的,因此先启动Zookeeper:> %Zookeeper_Home%/bin[b]/zkServer.sh start[/b]
在配置文件server.properties中把下面一句前面的注释去掉,然后启动Kafka服务器
[b] > #listeners=PLAINTEXT://:9092[/b]
[b] >[/b] bin/kafka-server-start.sh config/server.properties
接下来启动其他两个broker:
> cp config/server.properties config/server-1.properties
> cp config/server.properties config/server-2.properties
修改配置文件,broker.id不能重复
config/server-1.properties: broker.id=1 config/server-2.properties: broker.id=2
Step 3: Create a topic
创建一个TRAFFIC_LOG主题的broker,复制因子为3(因为有3个Kafka服务器集群),分区个数为1> bin/kafka-topics.sh --create --zookeeper 10.208.129.4:2181 --replication-factor 3 --partitions 1 --topic TRAFFIC_LOG
Step 5: Start a consumer
> bin/kafka-console-consumer.sh --zookeeper 10.208.129.4:2181/kafka --topic TRAFFIC_LOG --from-beginning
topic一定要写正确了,否则消费不到数据如果在终端看到之前接入的Thrift Source输出,那么整个Flume+Kafka算是跑通了
这里已经引入了Flume和Kafka,下一篇将介绍Kafka以及Flume和Kafka的区别
相关文章推荐
- Android studio 常用快捷键整理
- 我的第一个博客
- 51nod 1344 【前缀和】
- 关于如何安装lumerical 2016a破解版
- 每日问题之改变类文件的位置后,代码运行不成功
- 启用apache,发现80端口被占用【已解决】
- python的sys.stdout重定向
- 机器学习(周志华)习题解答4.3: Python小白详解ID3决策树的实现
- 朴素贝叶斯的推理学习算法
- 使用Nginx+Keepalived组建高可用负载平衡Web server集群
- 凸包Graham扫描法->HDU3847
- 51nod 1347 【水】
- JSPatch 中 defineClass 中覆盖方法的使用
- typedef 的用法
- spring 简单操作数据库
- Real-Time Rendering-附录B 三角函数
- UVa 1330 City Game(DP)
- GH0ST编译步骤
- nginx+keepalive主从双机热备+自动切换解决方案
- objdump的使用