Windows下Zookeeper启动错误Invalid arguments, exiting abnormally

目录

现象

原因

zkServer.sh 代码片段

zkServer.cmd代码片段

源码分析

解决方法


现象

启动命令

d:\zk>bin\zkServer.cmd start

 

错误

d:\zk>call "D:\DEV\JAVA\JDK"\bin\java "-Dzookeeper.log.dir=d:\zk\bin\..\logs" "-Dzookeeper.root.logger=INFO,CONSOLE" "-Dzookeeper.log.file=zookeeper-YQY-server-DUCKLING-S.log" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%p /t /f" -cp "d:\zk\bin\..\build\classes;d:\zk\bin\..\build\lib\*;d:\zk\bin\..\*;d:\zk\bin\..\lib\*;d:\zk\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "d:\zk\bin\..\conf\zoo.cfg" start
2021-06-02 18:41:21,899 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-06-02 18:41:21,901 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2021-06-02 18:41:21,902 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2021-06-02 18:41:21,902 [myid:] - WARN  [main:QuorumPeerMain@125] - Either no config or no quorum defined in config, running  in standalone mode
2021-06-02 18:41:21,903 [myid:] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2021-06-02 18:41:21,952 [myid:] - ERROR [main:ZooKeeperServerMain@66] - Invalid arguments, exiting abnormally
java.lang.NumberFormatException: For input string: "d:\zk\bin\..\conf\zoo.cfg"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.parseInt(Integer.java:615)
        at org.apache.zookeeper.server.ServerConfig.parse(ServerConfig.java:63)
        at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:103)
        at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:64)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:128)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
2021-06-02 18:41:21,954 [myid:] - INFO  [main:ZooKeeperServerMain@67] - Usage: ZooKeeperServerMain configfile | port datadir [ticktime] [maxcnxns]
Usage: ZooKeeperServerMain configfile | port datadir [ticktime] [maxcnxns]

原因

为何Linux可以,而Windows下不行呢?这里分别打开了两个版本的启动文件。

zkServer.sh 代码片段

可以看到,该脚本接收了输入参数,并且在start分之后到调用了java程序。

相当于start是针对zkServer.sh的,而不是针对zk主类 org.apache.zookeeper.server.quorum.QuorumPeerMain的。

case $1 in
start)
    echo  -n "Starting zookeeper ... "
    if [ -f "$ZOOPIDFILE" ]; then
      if kill -0 `cat "$ZOOPIDFILE"` > /dev/null 2>&1; then
         echo $command already running as process `cat "$ZOOPIDFILE"`.
         exit 1
      fi
    fi
    nohup "$JAVA" $ZOO_DATADIR_AUTOCREATE "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" \
    "-Dzookeeper.log.file=${ZOO_LOG_FILE}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
    -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
    -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &
    if [ $? -eq 0 ]
    then
      case "$OSTYPE" in
      *solaris*)
        /bin/echo "${!}\\c" > "$ZOOPIDFILE"
        ;;
      *)
        /bin/echo -n $! > "$ZOOPIDFILE"
        ;;
      esac
      if [ $? -eq 0 ];
      then
        sleep 1
        pid=$(cat "${ZOOPIDFILE}")
        if ps -p "${pid}" > /dev/null 2>&1; then
          echo STARTED
        else
          echo FAILED TO START
          exit 1
        fi
      else
        echo FAILED TO WRITE PID
        exit 1
      fi
    else
      echo SERVER DID NOT START
      exit 1
    fi
    ;;

除此之外,还可以看到支持start-foreground、stop、restart、status等操作。

 

zkServer.cmd代码片段

@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.

setlocal
call "%~dp0zkEnv.cmd"

set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOO_LOG_FILE=zookeeper-%USERNAME%-server-%COMPUTERNAME%.log

echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" "-Dzookeeper.log.file=%ZOO_LOG_FILE%" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%%%p /t /f" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*

endlocal

cmd中,并没有对输入的参数进行任何解析,而是直接将其交给了org.apache.zookeeper.server.quorum.QuorumPeerMain类。

源码分析

根据错误提示,直接找到源码。

org.apache.zookeeper.server.ServerConfig.parse(ServerConfig.java:63)

 

因版本不通过,代码行数可能有所差异,可以根据方法名称找到关键信息。

 

https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerConfig.java

    /**
     * Parse arguments for server configuration
     * @param args clientPort dataDir and optional tickTime and maxClientCnxns
     * @throws IllegalArgumentException on invalid usage
     */
    public void parse(String[] args) {
        if (args.length < 2 || args.length > 4) {
            throw new IllegalArgumentException("Invalid number of arguments:" + Arrays.toString(args));
        }

        clientPortAddress = new InetSocketAddress(Integer.parseInt(args[0]));
        dataDir = new File(args[1]);
        dataLogDir = dataDir;
        if (args.length >= 3) {
            tickTime = Integer.parseInt(args[2]);
        }
        if (args.length == 4) {
            maxClientCnxns = Integer.parseInt(args[3]);
        }
    }

根据异常综合判断,可能与提交的参数的数量、参数的名称有关。

todo 这里没能从代码中分析出具体的失败原因,需要把zk代码下到本地IDE上运行才能准确判断。

当前时间有限,先把坑挖出来,日后再填。

 

解决方法

windows下,直接使用zkServer.cmd,不需要加参数即可启动。

d:\zk>bin\zkServer.cmd

 

d:\zk>bin\zkServer.cmd

d:\zk>call "D:\DEV\JAVA\JDK"\bin\java "-Dzookeeper.log.dir=d:\zk\bin\..\logs" "-Dzookeeper.root.logger=INFO,CONSOLE" "-Dzookeeper.log.file=zookeeper-YQY-server-DUCKLING-S.log" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%p /t /f" -cp "d:\zk\bin\..\build\classes;d:\zk\bin\..\build\lib\*;d:\zk\bin\..\*;d:\zk\bin\..\lib\*;d:\zk\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "d:\zk\bin\..\conf\zoo.cfg"
2021-06-02 18:44:13,309 [myid:] - INFO  [main:QuorumPeerConfig@133] - Reading configuration from: d:\zk\bin\..\conf\zoo.cfg
2021-06-02 18:44:13,322 [myid:] - INFO  [main:QuorumPeerConfig@385] - clientPortAddress is 0.0.0.0/0.0.0.0:2181
2021-06-02 18:44:13,322 [myid:] - INFO  [main:QuorumPeerConfig@389] - secureClientPort is not set
2021-06-02 18:44:13,325 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-06-02 18:44:13,326 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2021-06-02 18:44:13,327 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2021-06-02 18:44:13,327 [myid:] - WARN  [main:QuorumPeerMain@125] - Either no config or no quorum defined in config, running  in standalone mode
2021-06-02 18:44:13,328 [myid:] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2021-06-02 18:44:13,376 [myid:] - INFO  [main:QuorumPeerConfig@133] - Reading configuration from: d:\zk\bin\..\conf\zoo.cfg
2021-06-02 18:44:13,377 [myid:] - INFO  [main:QuorumPeerConfig@385] - clientPortAddress is 0.0.0.0/0.0.0.0:2181
2021-06-02 18:44:13,377 [myid:] - INFO  [main:QuorumPeerConfig@389] - secureClientPort is not set
2021-06-02 18:44:13,378 [myid:] - INFO  [main:ZooKeeperServerMain@117] - Starting server
2021-06-02 18:44:13,398 [myid:] - INFO  [main:Environment@109] - Server environment:zookeeper.version=3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT
2021-06-02 18:44:13,398 [myid:] - INFO  [main:Environment@109] - Server environment:host.name=Duckling-S
2021-06-02 18:44:13,398 [myid:] - INFO  [main:Environment@109] - Server environment:java.version=1.8.0_271
2021-06-02 18:44:13,399 [myid:] - INFO  [main:Environment@109] - Server environment:java.vendor=Oracle Corporation
2021-06-02 18:44:13,401 [myid:] - INFO  [main:Environment@109] - Server environment:java.home=D:\DEV\JAVA\JDK\jre
2021-06-02 18:44:13,401 [myid:] - INFO  [main:Environment@109] - Server environment:java.class.path=d:\zk\bin\..\build\classes;d:\zk\bin\..\build\lib\*;d:\zk\bin\..\*;d:\zk\bin\..\lib\audience-annotations-0.5.0.jar;d:\zk\bin\..\lib\commons-cli-1.2.jar;d:\zk\bin\..\lib\jackson-annotations-2.9.0.jar;d:\zk\bin\..\lib\jackson-core-2.9.8.jar;d:\zk\bin\..\lib\jackson-databind-2.9.8.jar;d:\zk\bin\..\lib\javax.servlet-api-3.1.0.jar;d:\zk\bin\..\lib\jetty-http-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jetty-io-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jetty-security-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jetty-server-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jetty-servlet-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jetty-util-9.4.17.v20190418.jar;d:\zk\bin\..\lib\jline-2.11.jar;d:\zk\bin\..\lib\json-simple-1.1.1.jar;d:\zk\bin\..\lib\log4j-1.2.17.jar;d:\zk\bin\..\lib\netty-all-4.1.29.Final.jar;d:\zk\bin\..\lib\slf4j-api-1.7.25.jar;d:\zk\bin\..\lib\slf4j-log4j12-1.7.25.jar;d:\zk\bin\..\lib\zookeeper-3.5.5.jar;d:\zk\bin\..\lib\zookeeper-jute-3.5.5.jar;d:\zk\bin\..\conf
2021-06-02 18:44:13,402 [myid:] - INFO  [main:Environment@109] - Server environment:java.library.path=D:\DEV\JAVA\JDK\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\VanDyke Software\Clients\;D:\DEV\Oracle\product\12.2.0\client_1\bin;D:\Program Files (x86)\VMware\VMware Workstation\bin\;D:\DEV\CUDA\Development\bin;D:\DEV\CUDA\Development\libnvvp;C:\Program Files (x86)\Common Files\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\NVIDIA Corporation\Nsight Compute 2020.2.1\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\TortoiseSVN\bin;D:\DEV\JAVA\JDK\bin;C:\Users\YQY\.cargo\bin;C:\Users\YQY\AppData\Local\Microsoft\WindowsApps;;D:\DEV\Python\PyCharmCommunityEdition2020.2.3\bin;;D:\DEV\JAVA\idea\IntelliJIDEACommunityEdition2020.2.3\bin;;D:\DEV\VSCode\MicrosoftVSCode\bin;.
2021-06-02 18:44:13,402 [myid:] - INFO  [main:Environment@109] - Server environment:java.io.tmpdir=C:\Users\YQY\AppData\Local\Temp\
2021-06-02 18:44:13,402 [myid:] - INFO  [main:Environment@109] - Server environment:java.compiler=<NA>
2021-06-02 18:44:13,403 [myid:] - INFO  [main:Environment@109] - Server environment:os.name=Windows 10
2021-06-02 18:44:13,403 [myid:] - INFO  [main:Environment@109] - Server environment:os.arch=amd64
2021-06-02 18:44:13,403 [myid:] - INFO  [main:Environment@109] - Server environment:os.version=10.0
2021-06-02 18:44:13,404 [myid:] - INFO  [main:Environment@109] - Server environment:user.name=YQY
2021-06-02 18:44:13,404 [myid:] - INFO  [main:Environment@109] - Server environment:user.home=C:\Users\YQY
2021-06-02 18:44:13,404 [myid:] - INFO  [main:Environment@109] - Server environment:user.dir=d:\zk
2021-06-02 18:44:13,404 [myid:] - INFO  [main:Environment@109] - Server environment:os.memory.free=1456MB
2021-06-02 18:44:13,405 [myid:] - INFO  [main:Environment@109] - Server environment:os.memory.max=21824MB
2021-06-02 18:44:13,405 [myid:] - INFO  [main:Environment@109] - Server environment:os.memory.total=1472MB
2021-06-02 18:44:13,406 [myid:] - INFO  [main:ZooKeeperServer@938] - minSessionTimeout set to 4000
2021-06-02 18:44:13,406 [myid:] - INFO  [main:ZooKeeperServer@947] - maxSessionTimeout set to 40000
2021-06-02 18:44:13,407 [myid:] - INFO  [main:ZooKeeperServer@166] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir D:\zk\data\version-2 snapdir D:\zk\data\version-2
2021-06-02 18:44:13,427 [myid:] - INFO  [main:Log@193] - Logging initialized @267ms to org.eclipse.jetty.util.log.Slf4jLog
2021-06-02 18:44:13,520 [myid:] - WARN  [main:ContextHandler@1588] - o.e.j.s.ServletContextHandler@61832929{/,null,UNAVAILABLE} contextPath ends with /*
2021-06-02 18:44:13,520 [myid:] - WARN  [main:ContextHandler@1599] - Empty contextPath
2021-06-02 18:44:13,531 [myid:] - INFO  [main:Server@370] - jetty-9.4.17.v20190418; built: 2019-04-18T19:45:35.259Z; git: aa1c656c315c011c01e7b21aabb04066635b9f67; jvm 1.8.0_271-b09
2021-06-02 18:44:13,563 [myid:] - INFO  [main:DefaultSessionIdManager@365] - DefaultSessionIdManager workerName=node0
2021-06-02 18:44:13,563 [myid:] - INFO  [main:DefaultSessionIdManager@370] - No SessionScavenger set, using defaults
2021-06-02 18:44:13,566 [myid:] - INFO  [main:HouseKeeper@149] - node0 Scavenging every 600000ms
2021-06-02 18:44:13,573 [myid:] - INFO  [main:ContextHandler@855] - Started o.e.j.s.ServletContextHandler@61832929{/,null,AVAILABLE}
2021-06-02 18:44:13,759 [myid:] - INFO  [main:AbstractConnector@292] - Started ServerConnector@15975490{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2021-06-02 18:44:13,759 [myid:] - INFO  [main:Server@410] - Started @606ms
2021-06-02 18:44:13,760 [myid:] - INFO  [main:JettyAdminServer@112] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2021-06-02 18:44:13,764 [myid:] - INFO  [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2021-06-02 18:44:13,766 [myid:] - INFO  [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 2 selector thread(s), 24 worker threads, and 64 kB direct buffers.
2021-06-02 18:44:13,768 [myid:] - INFO  [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181
2021-06-02 18:44:13,779 [myid:] - INFO  [main:ZKDatabase@117] - zookeeper.snapshotSizeFactor = 0.33
2021-06-02 18:44:13,785 [myid:] - INFO  [main:FileSnap@83] - Reading snapshot D:\zk\data\version-2\snapshot.0
2021-06-02 18:44:13,811 [myid:] - INFO  [main:FileTxnSnapLog@372] - Snapshotting: 0x12c to D:\zk\data\version-2\snapshot.12c
2021-06-02 18:44:13,825 [myid:] - INFO  [main:ContainerManager@64] - Using checkIntervalMs=60000 maxPerMinute=10000

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要解决Windows安装Zookeeper启动拒绝访问的问题,可以遵循以下步骤: 1. 确保你以管理员身份运行命令提示符或PowerShell。管理员权限是必要的,因为启动Zookeeper服务需要较高的权限。 2. 检查安装目录和配置文件的权限。确保你有足够的权限访问安装目录和Zookeeper的配置文件。如果权限不足,可以通过右键单击目录或文件,选择“属性”,然后选择“安全”选项卡来修改权限。 3. 检查Java环境变量是否正确设置。Zookeeper运行需要Java环境,确保你已正确设置了JAVA_HOME环境变量,并将其添加到了系统的PATH环境变量中。 4. 检查Zookeeper配置文件。在Zookeeper的配置文件(zoo.cfg)中,确保配置文件中指定的数据目录(dataDir)和日志目录(dataLogDir)存在,并且你有足够的权限访问这些目录。 5. 如果你使用了防火墙或安全软件,请确保它们没有阻止Zookeeper服务的访问。可以尝试禁用防火墙或安全软件,然后再次尝试启动Zookeeper服务。 通过以上步骤,你应该能够解决Windows安装Zookeeper启动拒绝访问的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Windowszookeeper服务启动失败](https://blog.csdn.net/qq_56204425/article/details/126661057)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [linux上安装zookeeper 启动和关闭的教程](https://download.csdn.net/download/weixin_38587005/14891181)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水牧羊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值