windows安装 kafka 解决(找不到或无法加载主类问题)

1.kafka需要jdk 8版本 u131以上,先将jdk升级一下,配置好环境变量。我这里选择 8u191 。

2.kafka需要Zookeeper做底层支持,需要先安装Zookeeper
下载地址:https://zookeeper.apache.org/releases.html
下载后,解压放在目录D:\king(本文所用的目录)下,关于zookeeper以及kafka的目录,路径中最好不要出现空格,比如D:\Program Files,尽量别用,运行脚本时会有问题。(当然问题可以解决,就是修改脚本在相应的路径引用添加双引号)
①进入zookeeper的相关设置所在的文件目录,D:\king\zookeeper-3.4.10\conf
②将"zoo_sample.cfg"重命名为"zoo.cfg"
③打开zoo.cfg(至于使用什么编辑器,根据自己喜好选即可),找到并编辑:

dataDir=/tmp/zookeeper  改为  dataDir=D:/king/zookeeper-3.4.10/data
(路径仅为示例,具体可根据需要配置)

这里注意,路径要么是"/"分割,要么是转义字符"\\",这样会生成正确的路径(层级,子目录)。

④与配置jre类似,在系统环境变量中添加:

    a.系统变量中添加ZOOKEEPER_HOME=D:\king\zookeeper-3.4.10

    b.编辑系统变量中的path变量,增加%ZOOKEEPER_HOME%\bin

⑤在zoo.cfg文件中修改默认的Zookeeper端口(默认端口2181)

这是本文最终的zoo.cfg文件的内容:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=D:/king/zookeeper-3.4.10/data
#dataDir=D:\\king\\zookeeper-3.4.10\\data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

2.1 Zookeeper启动很容易,一般不会出现问题,
直接双击打开 “D:\King\zookeeper-3.4.13\bin\zkServer.cmd” 运行
Zookeeper已经运行在2181端口上
表明Zookeeper已经运行在2181端口上

3.安装kafka
下载地址:http://kafka.apache.org/downloads

要下载Binary downloads这个类型,不要下载源文件,这种方便使用。下载后,解压放在D:\king目录下。

①进入kafka配置文件所在目录,D:\king\kafka_2.11-0.9.0.1\config

②编辑文件"server.properties",找到并编辑:

 	log.dirs=/tmp/kafka-logs  改成  log.dirs=D:/King/kafka_2.12-2.1.0/kafka-logs

	同样注意:路径要么是"/"分割,要么是转义字符"\\",这样会生成正确的路径(层级,子目录)。错误路径情况可自行尝试,文件夹名为这种形式:king\\kafka_2.11-0.9.0.1kafka-logs

③在server.properties文件中,zookeeper.connect=localhost:2181代表kafka所连接的zookeeper所在的服务器IP以及端口,可根据需要更改。本文在同一台机器上使用,故不用修改。

④kafka会按照默认配置,在9092端口上运行,并连接zookeeper的默认端口2181。
⑤运行之前有一个注意事项,kafka运行脚本中有一个classpath要求Java_hone路径中不能有空格,否则会运行错误,如果不想修改jdk路径,
那么打开 “D:\King\kafka_2.12-2.1.0\bin\windows\kafka-run-class.bat” 将其中的 -cp %CLASSPATH% 改为 -cp “%CLASSPATH%” (加双引号) 其他的classpath不要加双引号 ,改了也会出问题。
如图
kafka找不到或无法加载主类问题解决办法

4.运行kafka
提示:首先配置完成电脑最好重启一下。然后请确保启动kafka服务器前,Zookeeper实例已经在运行,因为kafka的运行是需要zookeeper这种分布式应用程序协调服务。

①进入kafka安装目录D:\king\kafka_2.11-0.9.0.1

②按下shift+鼠标右键,选择"在此处打开命令窗口",打开命令行。

③在命令行中输入:.\bin\windows\kafka-server-start.bat .\config\server.properties 回车。

kafka启动图示

5.然后 ojbk

猜你喜欢

转载自blog.csdn.net/w4187402/article/details/84848201
今日推荐