1 在windows系统上配置java环境
kafka服务依赖于java,所以第一步需要在Windows上配置java环境,这里就不赘述了。
2 下载kafka
从kafka官方下载页面 下载kafka的二进制版本,这里以kafka_2.12-2.6.2版本为例。
下载之后解压,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
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论
57