• 问题反馈可发送邮件到stubbornhuang@qq.com

  • 本站由于前段时间遭受到大量临时和国外邮箱注册,所以对可注册的邮箱类型进行了限制!

  • 欢迎大家交换友链,可在https://www.stubbornhuang.com/申请友情链接进行友链交换申请!

  • 如果觉得本站的内容有帮助,可以考虑打赏博主哦!

  • 感谢大家访问本站,希望本站的内容可以帮助到大家!

  • 工资「喂饱肚子」,副业「养活灵魂」!

  • 本站会放置Google广告用于维持域名以及网站服务器费用。

  • 计算机图形学与计算几何经典必备书单整理,下载链接可参考:https://www.stubbornhuang.com/1256/

  • 在本站开通年度VIP,无限制下载本站资源和阅读本站文章

Windows下搭建kafka服务器

Windows编程 发布于2025-04-22 阅读 5,130次 0次评论 0次点赞 本文共3032个字,阅读需要8分钟。

1 在windows系统上配置java环境

kafka服务依赖于java,所以第一步需要在Windows上配置java环境,这里就不赘述了。

2 下载kafka

kafka官方下载页面 下载kafka的二进制版本,这里以kafka_2.12-2.6.2版本为例。

Windows下搭建kafka服务器-第0张图片

下载之后解压,windows系统的相关脚本主要在bin/windows目录下。需要注意的是,最好解压到英文目录下,并且目录层级不能太深 。Kafka包已经自带了Zookeeper,因此不必另外下载。

3 启动kafka服务

我们需要先启动zookeeper,然后再启动kafka服务,首先进入到kafka的解压目录

cd E:\software\kafka\kafka_2.12-2.6.2

然后首先启动zookeeper服务

bin\windows\zookeeper-server-start.bat config\zookeeper.properties

然后启动kafka服务

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

3.1 Windows 11 启动kafka服务报'wmic' 不是内部或外部命令,也不是可运行的程序 或批处理文件错误

在Windows 11的高版本,由于在系统中移除了wmic,所以在启动低版本kafka服务时会出现以下错误

'wmic' 不是内部或外部命令,也不是可运行的程序 或批处理文件错误

这个时候我们只需要将bin/windows/kafka-server-start.bat这个文件的内容从

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

IF [%1] EQU [] (
    echo USAGE: %0 server.properties
    EXIT /B 1
)

SetLocal
IF ["%KAFKA_LOG4J_OPTS%"] EQU [""] (
    set KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:%~dp0../../config/log4j.properties
)
IF ["%KAFKA_HEAP_OPTS%"] EQU [""] (
    rem 64-bit OS
    set KAFKA_HEAP_OPTS=-Xmx1G -Xms1G
)
"%~dp0kafka-run-class.bat" kafka.Kafka %*
EndLocal

修改为

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

IF [%1] EQU [] (
    echo USAGE: %0 server.properties
    EXIT /B 1
)

SetLocal
IF ["%KAFKA_LOG4J_OPTS%"] EQU [""] (
    set KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:%~dp0../../config/log4j.properties
)
IF ["%KAFKA_HEAP_OPTS%"] EQU [""] (
    rem detect OS architecture
    wmic os get osarchitecture | find /i "32-bit" >nul 2>&1
    IF NOT ERRORLEVEL 1 (
        rem 32-bit OS
        set KAFKA_HEAP_OPTS=-Xmx512M -Xms512M
    ) ELSE (
        rem 64-bit OS
        set KAFKA_HEAP_OPTS=-Xmx1G -Xms1G
    )
)
"%~dp0kafka-run-class.bat" kafka.Kafka %*
EndLocal

保存退出,然后重启使用启动命令启动服务即可。

4 kafka使用

4.1 创建topic

在kafka中创建一个topic,可使用以下命令

bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic topic名字

4.2 查看topic列表

bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092

参考链接

欢迎扫码关注我的微信公众号,及时获取文章更新

微信公众号二维码

本文作者:StubbornHuang

版权声明:本文为站长原创文章,如果转载请注明原文链接!

原文标题:Windows下搭建kafka服务器

原文链接:https://www.stubbornhuang.com/3162/

发布于:2025年04月22日 11:13:39

修改于:2025年04月22日 11:13:39

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

文章末尾
上一篇
Python - moviepy库在读取视频时出现了'utf8' codec can't decode byte 0xce in position 1873: invalid continuation byte错误
Python
下一篇
宝塔面板无插件迁移同域名WordPress网站全流程详解
WordPress
当前分类随机文章推荐

发表评论

您必须 [ 登录 ] 才能发表留言!

关注我们的公众号

微信公众号