kafka之一:Windows上搭建Kafka运行环境

搭建环境

1. 安装JDK

1.1 安装文件:http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html下载Server JRE.
1.2 安装完成后需要添加以下的环境变量(右键点击“我的电脑” -> "高级系统设置" -> "环境变量" ):

JAVA_HOME: C:\Java\jdk1.8.0_31(这个是默认安装路径,如果安装过程中更改了安装目录,把更改后的路径填上就行了)

PATH: 在现有的值后面添加"; %JAVA_HOME%\bin"

1.3 打开cmd运行 "java -version" 查看当前系统Java的版本:

2. 安装Zookeeper

Kafka的运行依赖于Zookeeper,所以在运行Kafka之前我们需要安装并运行Zookeeper

2.1 下载安装文件: http://zookeeper.apache.org/releases.html
2.2 解压文件(本文解压到 D:\soft\zookeeper\zookeeper-3.3.6)
2.3 打开D:\soft\zookeeper\zookeeper-3.3.6\conf,把zoo_sample.cfg重命名成zoo.cfg
2.4 从文本编辑器里打开zoo.cfg
调整配置如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=D:\\tmp\\data\\zookeeper
#日志位置
dataLogDir=D:\\tmp\\logs\\zookeeper
# the port at which the clients will connect
clientPort=2181
2.5 运行Zookeeper: 打开bin目录cmd然后执行
zkserver 

3. 安装并运行Kafka

3.1 下载安装文件: http://kafka.apache.org/downloads.html
3.2 解压文件(本文解压到 D:\soft\kafka\kafka_2.10-0.10.1.1)
3.3 打开D:\soft\kafka\kafka_2.10-0.10.1.1\config
3.4 从文本编辑器里打开 server.properties
3.5 把 log.dirs的值改成 “log.dirs=D:\soft\kafka\kafka_2.10-0.10.1.1\kafka-logs”
3.6 打开cmd
3.7 进入kafka文件目录: cd  D:\soft\kafka\kafka_2.10-0.10.1.1\bin
3.8 输入并执行以打开kafka:
D:\soft\kafka\kafka_2.10-0.10.1.1\bin\windows>kafka-server-start.bat ..\..\config\server.properties

结果:

4. 创建topics

4.1 打开cmd 并进入G:\kafka_2.11-0.10.0.1\bin\windows
4.2 创建一个topic:
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

 

查看创建结果:

D:\soft\kafka\kafka_2.10-0.10.1.1\bin\windows>kafka-topics.bat --list --zookeeper localhost:2181

 

5. 打开一个Producer:

D:\soft\kafka\kafka_2.10-0.10.1.1\bin\windows>kafka-console-producer.bat --broker-list localhost:9092 --topic test

6. 打开一个Consumer:

D:\soft\kafka\kafka_2.10-0.10.1.1\bin\windows>kafka-console-consumer.bat --zookeeper localhost:2181 --topic test
然后就可以在Producer控制台窗口输入消息了。在消息输入过后,很快Consumer窗口就会显示出Producer发送的消息:

 

 
至此,Kafka运行环境的搭建就完成了:-)
posted on 2015-08-05 16:48  duanxz  阅读(814)  评论(0编辑  收藏  举报