zk配置Error: JAVA_HOME is incorrectly set.

windows10 环境下本机安装zookeeper。

公司测试服务器的zookeeper 因为一些未知原因,会偶尔挂掉,然后考虑本机安装zookeeper服务,用于程序开发。

一. 下载zookeeper 官网地址:http://mirror.bit.edu.cn/apache/zookeeper/

一开始选择的是zookeeper-3.5.5版本,后来再启动时,提示加载不到主类,找了些资料,也没有解决,然后换了zookeeper-3.4.14 试了下,可以启动服务并应用。

我这边下载安装的是zookeeper-3.4.14版本(zookeeper-3.4.14.tar.gz ) http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/

二. 安装

2.1 将压缩包解压到D盘 目录为:D:\zookeeper-3.4.14。

2.2 修改D:\zookeeper-3.4.14\conf 下的zoo_sample.cfg 文件。
1)首先将文件名改成 zoo.cfg。
2)打开 zoo.cfg 文件 ,指定临时数据目录,修改dataDir=/tmp/zookeeper 为 dataDir=D:/zookeeper-3.4.14/tmp/zookeeper。
3)其他属性后期可根据需要修改。

三. 启动
通过 cmd 进入dos命令窗口。命令窗口模式进入zookeeper的bin目录下,输入zkServer.cmd 回车。
C:\Users\hzhb>e:

D:>cd zookeeper-3.4.14/bin

D:\zookeeper-3.4.14\bin>zkServer.cmd
Error: JAVA_HOME is incorrectly set.

D:\zookeeper-3.4.14\bin>call “-Dzookeeper.log.dir=D:\zookeeper-3.4.14\bin…” “-Dzookeeper.root.logger=INFO,CONSOLE” -cp “D:\zookeeper-3.4.14\bin…\build\classes;D:\zookeeper-3.4.14\bin…\build\lib*;D:\zookeeper-3.4.14\bin…*;D:\zookeeper-3.4.14\bin…\lib*;D:\zookeeper-3.4.14\bin…\conf” org.apache.zookeeper.server.quorum.QuorumPeerMain “D:\zookeeper-3.4.14\bin…\conf\zoo.cfg”
‘"-Dzookeeper.log.dir=D:\zookeeper-3.4.14\bin…"’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。

D:\zookeeper-3.4.14\bin>endlocal

D:\zookeeper-3.4.14\bin>

。。。。。报错了。。。。。

根据异常信息 提示JAVA_HOME 设置错误,下面要设置下JAVA_HOME。

打开 D:\zookeeper-3.4.14\bin 下的zkEnv.cmd 文件。然后重新指定JAVA_HOME。

删掉原来的 set JAVA_HOME=%JAVA_HOME:"=% ,然后修改如下:

@REM setup java environment variables
set JAVA_HOME=“C:\Program Files\Java\jdk1.8.0_131”

if not defined JAVA_HOME (
echo Error: JAVA_HOME is not set.
goto :eof
)

if not exist “%JAVA_HOME%”\bin\java.exe (
echo Error: JAVA_HOME is incorrectly set.
goto :eof
)

REM strip off trailing \ from JAVA_HOME or java does not start
if “%JAVA_HOME:~-1%” EQU “” set “JAVA_HOME=%JAVA_HOME:~0,-1%”

set JAVA="%JAVA_HOME%"\bin\java

然后 回到命令窗口 重新启动 如下:
D:\zookeeper-3.4.14\bin>zkServer.cmd
系统找不到指定的路径。
Error: JAVA_HOME is incorrectly set.

D:\zookeeper-3.4.14\bin>call “-Dzookeeper.log.dir=D:\zookeeper-3.4.14\bin…” “-Dzookeeper.root.logger=INFO,CONSOLE” -cp “D:\zookeeper-3.4.14\bin…\build\classes;D:\zookeeper-3.4.14\bin…\build\lib*;D:\zookeeper-3.4.14\bin…*;D:\zookeeper-3.4.14\bin…\lib*;D:\zookeeper-3.4.14\bin…\conf” org.apache.zookeeper.server.quorum.QuorumPeerMain “D:\zookeeper-3.4.14\bin…\conf\zoo.cfg”
‘"-Dzookeeper.log.dir=D:\zookeeper-3.4.14\bin…"’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。

D:\zookeeper-3.4.14\bin>endlocal

D:\zookeeper-3.4.14\bin>

。。。。。发现还是报错 系统找不到指定的路径。。。。。。。

然后看配置文件是
if not exist “%JAVA_HOME%”\bin\java.exe (
echo Error: JAVA_HOME is incorrectly set.
goto :eof
)
报的错误,将路径修改下,去掉 “%JAVA_HOME%” 的双引号 改成 %JAVA_HOME% 如下:

@REM setup java environment variables
set JAVA_HOME=“C:\Program Files\Java\jdk1.8.0_131”

if not defined JAVA_HOME (
echo Error: JAVA_HOME is not set.
goto :eof
)

if not exist %JAVA_HOME%\bin\java.exe (
echo Error: JAVA_HOME is incorrectly set.
goto :eof
)

REM strip off trailing \ from JAVA_HOME or java does not start
if “%JAVA_HOME:~-1%” EQU “” set “JAVA_HOME=%JAVA_HOME:~0,-1%”

set JAVA=%JAVA_HOME%\bin\java

然后 回到命令窗口 重新启动 如下:
D:\zookeeper-3.4.14\bin>zkServer.cmd
此时不应有 =“C:\Program Files\Java\jdk1.8.0_131”。

D:\zookeeper-3.4.14\bin>

。。。。。。
还是有问题,在这个地方,想了好一会也不清楚问题在哪里,后来分析下唯一可能出问题的地方 也就是
REM strip off trailing \ from JAVA_HOME or java does not start
if “%JAVA_HOME:~-1%” EQU “” set “JAVA_HOME=%JAVA_HOME:~0,-1%”
看下这句话大概是说如果JAVA_HOME满足什么条件,给JAVA_HOME赋值,个人觉着 JAVA_HOME 上面已经配好,可以不管这句,就把它删掉了。。。。。

然后 回到命令窗口 重新启动 如下:
D:\zookeeper-3.4.14\bin>zkServer.cmd

D:\zookeeper-3.4.14\bin>call “D:\java\JDK”\bin\java “-Dzookeeper.log.dir=D:\zookeeper-3.4.14\bin…” “-Dzookeeper.root.logger=INFO,CONSOLE” -cp “D:\zookeeper-3.4.14\bin…\build\classes;D:\zookeeper-3.4.14\bin…\build\lib*;D:\zookeeper-3.4.14\bin…*;D:\zookeeper-3.4.14\bin…\lib*;D:\zookeeper-3.4.14\bin…\conf” org.apache.zookeeper.server.quorum.QuorumPeerMain “D:\zookeeper-3.4.14\bin…\conf\zoo.cfg”
2019-11-20 15:04:07,148 [myid:] - INFO [main:QuorumPeerConfig@136] - Reading configuration from: D:\zookeeper-3.4.14\bin…\conf\zoo.cfg
2019-11-20 15:04:07,148 [myid:] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2019-11-20 15:04:07,148 [myid:] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2019-11-20 15:04:07,148 [myid:] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2019-11-20 15:04:07,148 [myid:] - WARN [main:QuorumPeerMain@116] - Either no config or no quorum defined in config, running in standalone mode
2019-11-20 15:04:07,210 [myid:] - INFO [main:QuorumPeerConfig@136] - Reading configuration from: D:\zookeeper-3.4.14\bin…\conf\zoo.cfg
2019-11-20 15:04:07,226 [myid:] - INFO [main:ZooKeeperServerMain@98] - Starting server
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:host.name=LAPTOP-RAHT8U4H
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.version=1.8.0_60
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.home=D:\java\JDK\jre
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.class.path=D:\zookeeper-3.4.14\bin…\build\classes;D:\zookeeper-3.4.14\bin…\build\lib*;D:\zookeeper-3.4.14\bin…\zookeeper-3.4.14.jar;D:\zookeeper-3.4.14\bin…\lib\audience-annotations-0.5.0.jar;D:\zookeeper-3.4.14\bin…\lib\jline-0.9.94.jar;D:\zookeeper-3.4.14\bin…\lib\log4j-1.2.17.jar;D:\zookeeper-3.4.14\bin…\lib\netty-3.10.6.Final.jar;D:\zookeeper-3.4.14\bin…\lib\slf4j-api-1.7.25.jar;D:\zookeeper-3.4.14\bin…\lib\slf4j-log4j12-1.7.25.jar;D:\zookeeper-3.4.14\bin…\conf
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.library.path=D:\java\JDK\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;“D:\java\JDK;\bin;D:\java\JDK;\jre\bin;”;C:\Users\DYF\AppData\Local\Microsoft\WindowsApps;;.
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.io.tmpdir=C:\Users\DYF\AppData\Local\Temp
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:java.compiler=
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:os.name=Windows 10
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:os.arch=amd64
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:os.version=10.0
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:user.name=DYF
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:user.home=C:\Users\DYF
2019-11-20 15:04:07,274 [myid:] - INFO [main:Environment@100] - Server environment:user.dir=D:\zookeeper-3.4.14\bin
2019-11-20 15:04:07,290 [myid:] - INFO [main:ZooKeeperServer@836] - tickTime set to 2000
2019-11-20 15:04:07,290 [myid:] - INFO [main:ZooKeeperServer@845] - minSessionTimeout set to -1
2019-11-20 15:04:07,290 [myid:] - INFO [main:ZooKeeperServer@854] - maxSessionTimeout set to -1
2019-11-20 15:04:07,352 [myid:] - INFO [main:ServerCnxnFactory@117] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2019-11-20 15:04:07,352 [myid:] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181

启动成功!

然后将项目中的原来的zookeeper 地址换成 当前配置 127.0.0.1:2181 即可。

你可能感兴趣的:(【Java学习】)