首页 资源列表 文章列表

无需安装Zookeeper!在Windows 10/11上部署Kafka 4.0模式

1、kafka 官网下载二进制文件 Binary download

https://kafka.apache.org/community/downloads/


文件名格式:kafka_2.13-4.0.0.tgz(2.13指Scala版本,4.0.0是Kafka版本)


KRaft模式

集群元数据初始化


# 生成集群唯一ID(示例输出)

kafka-storage.bat random-uuid

> 3j3Mo7pURcew1KeUKcvCZw

# 格式化存储目录(注意路径转换)

kafka-storage.bat format --standalone -t [你的集群ID] -c ..\..\config\server.properties


服务配置文件优化

修改config/server.properties时重点关注这些参数:


# 监听地址(必须显式设置)

listeners=PLAINTEXT://:9092


# 日志存储路径(避免使用Program Files)

log.dirs=C:\\kafka\\logs


# 单节点模式关键配置

process.roles=broker

controller.quorum.voters=1@localhost:9093

node.id=1


服务启停与验证

启动服务的正确姿势

在bin/windows目录下执行:


# 前台启动(推荐调试时使用)

kafka-server-start.bat ..\..\config\server.properties

# 后台启动(长期运行)

start /B kafka-server-start.bat ..\..\config\server.properties > nul 2>&1


基础功能测试

打开两个PowerShell窗口分别执行:

# 生产者窗口

kafka-console-producer.bat --bootstrap-server localhost:9092 --topic test-topic

# 消费者窗口

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test-topic --from-beginning