Starting Zookeeper Cluster. Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
Asked Answered
C

7

31

(I'm running on CentOS 5.8). I've been following the direction for a Clustered (Multiserver) Zookeeper Set-up, but getting an error when I try to start up my server. When I run the command as described in the documentation:

java -cp zookeeper-3.4.6.jar:lib/log4j-1.2.16.jar:conf \ org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg 

I get the error:

Error: Could not find or load main class  org.apache.zookeeper.server.quorum.QuorumPeerMain

I have my files location as such and am running from the ~/zookeeper-3.4.6 directory:

~/zookeeper-3.4.6/zookeeper-3.4.6.jar 
~/zookeeper-3.4.6/conf/zoo.cfg
~/zookeeper-3.4.6/data/myid
~/zookeeper-3.4.6/lib/log4j-1.2.16.jar
~/zookeeper-3.4.6/bin/zkServer.sh

Does anyone know why this error is happening? I don't quite understand the arguments that are being passed, so it is hard for me to debug the path issue. As a side note, I've tried running ./zookeeper-3.4.6/bin/zkServer.sh start, which did successfully work, but the documentation seems to indicate that command is meant for a single-node instance.

Edit:

I was able to make some progress by modifying the command and taking out the :conf \ part, so now I'm running:

java -cp zookeeper-3.4.6.jar:lib/log4j-1.2.16.jar: org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg

I get a new error, but this is progress...

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFacto
ry
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.<clinit>(QuorumPeer
Main.java:64)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 1 more

which corresponds to lines 63 and 64 from QuorumPeerMain

public class QuorumPeerMain {
    private static final Logger LOG = LoggerFactory.getLogger(QuorumPeerMain.class);
Comprehensive answered 12/2, 2015 at 17:51 Comment(1)
8 years later and I get the same error :(Whin
N
3

You should be able to run zkServer.sh to get a clustered setup. It will use the same conf/zoo.cfg that you are providing manually, which will contain the cluster endpoints.

The best way to check what you are missing from your classpath (and see the proper java command) is to run the zkServer.sh you said worked for you.

When it starts up, check the actual command used like this:

ps -ef | grep zookeeper
Necolenecro answered 12/2, 2015 at 22:15 Comment(1)
Think you're right. Also, I figured out that I was using an out of date documentation for zookeeper. The recent one also specifies a slf4j jar which solves the problem in the second editComprehensive
S
110

I got the Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain, because I had downloaded the apache-zookeeper-X.X.X.tar.gz file and not the apache-zookeeper-X.X.X.bin.tar.gz file. Downloading, untarring and using the bin.tar file fixed it for me.

You can also build the binaries from the apache-zookeeper-X.X.X.tar.gz file; see the answer of @vincent.

Shaver answered 17/6, 2019 at 12:10 Comment(1)
Solution working on Windows 10 :) Thanks.Godless
M
35

This happens when you download and used apache-zookeeper-X.X.X.tar.gz, you should use apache-zookeeper-X.X.X-bin.tar.gz. this will surely solve this issue

Malathion answered 5/11, 2019 at 13:59 Comment(1)
what is the difference between these 2 files? bin.tar.gz and tar.gz? I see one is 8Mb, another is 3 MbAubreyaubrie
M
12

The issue can be solved by untaring apache-zookeeper-3.5.6-bin.tar.gz. Initially, I encountered the same error while untared/installed apache-zookeeper-3.5.6.tar.gz and executed /bin/zkServer.sh start

Please make sure you have downloaded apache-zookeeper-3.5.6-bin.tar.gz

Mayenne answered 13/1, 2020 at 12:0 Comment(1)
Please do not add signatures or politeness text into your posts. The former can be seen as spam, and thus lead to deletion, the latter is unnecessary noise in an otherwise professional sounding Q/A site.Infirmity
U
11

I got the same errors. I solved the error by check the README.md file in apache-zookeeper-[version].tar.gz Just type:

mvn clean install -DskipTests

then start the zookeeper. You will solve the error, too.

Uball answered 26/9, 2019 at 13:9 Comment(3)
This is the best answer. Switching to the "...bin.tar.gz" distribution isn't the correct option for everyone, which many of the other answers presume. (Those answers are akin to saying, "you should take a taxi" to someone asking "what's wrong with my car?)Saccular
this fixed it for me!Luralurch
This answer is not for me. "[ERROR] The goal you specified requires a project to execute but there is no POM in this directory". I am not a java developer. I cannot find any pom.xml under /zookeeper...Whin
N
3

You should be able to run zkServer.sh to get a clustered setup. It will use the same conf/zoo.cfg that you are providing manually, which will contain the cluster endpoints.

The best way to check what you are missing from your classpath (and see the proper java command) is to run the zkServer.sh you said worked for you.

When it starts up, check the actual command used like this:

ps -ef | grep zookeeper
Necolenecro answered 12/2, 2015 at 22:15 Comment(1)
Think you're right. Also, I figured out that I was using an out of date documentation for zookeeper. The recent one also specifies a slf4j jar which solves the problem in the second editComprehensive
M
2

I also get this error when try to run Apache Zookeper v3.5.5 on Windows:

Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

As said by @Onnonymous, I finish my problem by downloading the .bin.tar.gz (here) instead of .tar.gz version.

Mertens answered 1/8, 2019 at 14:18 Comment(0)
B
0

I am using apache-zookeeper-3.8.0-bin.tar.gz (Ubuntu 20.04) This has all the necessary files to successfully start the zookeeper process. specifying the other nodes in zoo.cfg file and starting the zookeeper automatically adds other nodes and starts the election process.

digital ocean has a good setup guide here setup zookeeper cluster

here's the zoo.cfg for reference

tickTime=2000
dataDir=/data/zookeeper
clientPort=2181
maxClientCnxns=60
initLimit=10
syncLimit=5
server.1=server1hostname/ip:2888:3888
server.2=server1hostname/ip:2888:3888
server.3=server1hostname/ip:2888:3888
Bridgettebridgewater answered 8/7, 2022 at 12:52 Comment(1)
I don't think that the digital ocean's setup guide would help me with this issue. They say to download zookeeper-3.4.13.tar.gz which is problematic. They should change it to zookeeper-3.4.13-bin.tar.gz. Downloading zookeeper-3.4.13-bin.tar.gz fixed my issue, like it says in the top voted answer.Whin

© 2022 - 2024 — McMap. All rights reserved.