Windows单机配置Kafka环境
2016-11-09 本文已影响5069人
sphsyv
首先确保机器已经安装好Zookeeper,Zookeeper安装参考 Windows单机配置Zookeeper环境
然后确保Zookeeper是正常启动状态
下载Kafka

下载后解压缩,我这里解压缩到了 D:\WorkSoftware\kafka_2.11_0.10.1.0 目录

首先建立一个空文件夹 logs

进入config目录,编辑 server.properties 文件

修改 log.dirs 属性部分的地址

然后在 D:\WorkSoftware\kafka_2.11_0.10.1.0 目录,按住shift+鼠标右键

然后输入下面命令
.\bin\windows\kafka-server-start.bat .\config\server.properties

回车,执行命令

如果出现错误,我这里分析是CLASSPATH没有配置正确,那么,先设置CLASSPATH,然后再执行
SET CLASSPATH=.;


测试一下,首先进入 D:\WorkSoftware\kafka_2.11-0.10.1.0\bin\windows 目录,然后在当前目录打开命令窗口

输入下面命令,创建一个topic
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test.topic
如果还遇到无法加载类等错误,还是先设置CLASSPATH


打开一个Producer
kafka-console-producer.bat --broker-list localhost:9092 --topic test.topic

这三个窗口不关闭的情况下(zookeeper/kafka/producer),再次开启一个命令窗口(还是在kafka目录右键打开),输入下面命令,开启Consumer
kafka-console-consumer.bat --zookeeper localhost:2181 --topic test.topic

这样,这里就有4个命令窗口

分别是
- Zookeeper
- Kafka
- Producer
- Consumer
下面,我们在3号窗口(Producer)输入一些字符,就会看到4号窗口马上就收到消息

至此,Kafka的Windows单机环境搭建完毕