Java – Unable to get the ZooKeeper cluster to work, elections will never happen

Unable to get the ZooKeeper cluster to work, elections will never happen… here is a solution to the problem.

Unable to get the ZooKeeper cluster to work, elections will never happen

This is my first time trying ZooKeeper, and while I can easily set it up to run on a single machine, having it run in a cluster of two machines doesn’t work at all. I thought there might be a problem with my config, but it looks like I can’t find it.

Here are the logs for server 1

Here are the logs for server 2

My two servers are configured as follows:

# 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.
dataDir=/var/lib/zookeeper
# the port at which the clients will connect
clientPort=2181
server.1=redis1:2888:3888
server.2=redis2:2888:3888

Any ideas on what the problem might be?

I’m running ZooKeeper 3.4.5 on an Ubuntu Linux machine running OpenJDK 7. Tried running on OpenJDK 6 and still experiencing the same issue.

Solution

The problem is that I have an even number of nodes and you need an odd number of nodes for elections (obviously). The documentation should be updated to cover this, as the basic example shows exactly 2 servers being configured.

Related Problems and Solutions