zookeeper not starting

In zoo.cfg file goto dataDir=/usr/zookeeper/data

In data folder create a file with name myid and write 1. Save the file and start zkServer

If you are running multiple instances, for every instance you need to create myid file in data folder and write with 1,2,3 respectively. Actually this is used for node leader election.


java.lang.NumberFormatException: For input string: "C:\Development\apps\zookeeper\zookeeper3.4.1\bin..\conf\zoo.cfg"

It seems you run the zkServer with the "start" and the location of the zoo.cfg file, namely, "C:\Development\apps\zookeeper\zookeeper3.4.1\bin..\conf\zoo.cfg", and another parameter, which adds up to 3 parameters:

./zkServer start C:\Development\apps\zookeeper\zookeeper3.4.1\bin..\conf\zoo.cfg xxx

So, the problem can be solved by simply remove the second and third parameter, which makes the command to:

./zkServer start

The reason behind this is because the classes(QuorumPeerMain, ZooKeeperServerMain) zkServer uses to initialize the zookeeper system accept various number of parameters and behave accordingly. When you feed two parameters to zkServer, the meaning behind the two parameters supposed to be port and datadir. Yeah, port should be a number, and here comes your bomb.

BTW, the bootstrap scripts are coming with help instructions when you execute them without any para.


Open the zkServer.cmd, find this line

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%" %*

and delete the %* at the end of the line. the new start cmd line should be:

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%"

then run zkServer start or zkServer. It should work now.


Explain:

In ZkServer source code. ZooKeeperServerMain.java

protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServerException {
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}

There're different parse methods for different argument length.

In case of one arguments, it will be took as config file path.

In case of multiple arguments, there is a fixed order.

1st arg(must): server port.
2nd arg(must): dataDir
3rd arg(optional): tickTime
4th arg(optional): maxClientCnxns

So back to zkServer.cmd, there're two placeholder in the arguments position.

%ZOOMAIN% "%ZOOCFG%" %*

I believe the developer expect a space for the %*, so it'll only one argument.

However, for most zk user. they're used to use zkServer start to start the server.

and finally, cmd turn out to be:

org.apache.zookeeper.server.quorum.QuorumPeerMain "C:\Users\...\scoop\apps\zookeeper\current\bin\..\conf\zoo.cfg" "start"

Two arguments are used. the 1st argument, the config path here, is took as port number. and then we have the exception.

More, how about using zkServer directly to start zooKeeper?

In my case, I was facing the same problem. Though we dont have any arguments. the zkServer.cmd still pass an empty string to the main method. like this:

org.apache.zookeeper.server.quorum.QuorumPeerMain "C:\Users\...\scoop\apps\zookeeper\current\bin\..\conf\zoo.cfg" ""

Conclusion: Just delete the redundant placeholder %*


just omit the "start" parameter and call "bin\zkServer" instead.