windows下启动kafka

kafka 与zookeeper 对应版本

kafka版本 springboot版本
kafka_2.12-2.4.0 zookeeper-3.5.6.jar
kafka_2.12-2.3.1 zookeeper-3.4.14.jar springboot2.2.2
kafka_2.12-2.3.0 zookeeper-3.4.14.jar springboot2.2.2
kafka_2.12-1.1.1 zookeeper-3.4.10.jar
kafka_2.12-1.1.0 zookeeper-3.4.10.jar
kafka_2.12-1.0.2 zookeeper-3.4.10.jar
kafka_2.12-1.0.0 zookeeper-3.4.10.jar
kafka_2.12-0.11.0.0 zookeeper-3.4.10.jar
kafka_2.12-0.10.2.2 zookeeper-3.4.9.jar
kafka_2.11-0.10.0.0 zookeeper-3.4.6.jar
kafka_2.11-0.9.0.0 zookeeper-3.4.6.jar

安装JDK

链接: http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载JDK
配置环境变量

windows下启动kafka_第1张图片

安装ZOOKEEPER

下载安装文件: http://zookeeper.apache.org/releases.html
用tar -zxvf 解压文件 (用的linux子系统)
打开zookeeper-3.4.13\conf,
把zoo_sample.cfg重命名成zoo.cfg
把zoo.cfg中dataDir的值改成
“./zookeeper-3.4.13/data”
添加环境变量并执行zkserver

windows下启动kafka_第2张图片

安装并运行KAFKA

下载安装文件: http://kafka.apache.org/downloads.html
解压文件 tar -zxvf (linux 子系统解压)
打开kafka_2.11-2.0.0\config
从文本编辑器里打开 server.properties
把 log.dirs的值改成
“./logs”
打开cmd
进入kafka文件目录:
 cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0(kafka目录)
输入并执行:
.\bin\windows\kafka-server-start.bat .\config\server.properties
遇到的启动问题zookeeper 拒绝连接
// An highlighted block
  需要将kafka下config的server.properties文件中改为zookeeper启动地址
  zookeeper.connect=0.0.0.0:2181  (指定具体的ip)
整合springboot时遇到连接失败问题
// An highlighted block
  需要将kafka下config的server.properties文件中新增host.name
 ############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092
 host.name=127.0.0.1

创建TOPICS 并测试

打开cmd 并进入
cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows
创建一个topic:
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
打开一个PRODUCER:
cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows
kafka-console-producer.bat --broker-list localhost:9092 --topic test
打开一个CONSUMER:
cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
测试

windows下启动kafka_第3张图片

你可能感兴趣的:(zookeeper,kafka,java)