Maurício Linhares
Maurício Linhares

Reputation: 40333

Can't get ZooKeeper cluster to work, election never happens

This is my first time trying out ZooKeeper and while I could easily set it up for running in a single machine, getting it to run in a cluster of two machines is not working at all. I think it might be something wrong with my configuration, but doesn't look like I can find it.

Here are the logs for server 1

Here are the logs for server 2

And my configuration is as follows for both servers:

# 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 issue could be?

I'm running ZooKeeper 3.4.5 in an Ubuntu Linux box running OpenJDK 7. Tried to run on OpenJDK 6 but still got the same issue.

Upvotes: 2

Views: 2122

Answers (2)

phunt
phunt

Reputation: 530

Your config is invalid, specifically

server.1=redis1:2888:3888
server.2=redis1:2888:3888

if you run two instances on the same host you need to have different port numbers for each, better would be something like

server.1=localhost:3181:4181
server.2=localhost:3182:4182

Note that you should have the same server.# config for both server's config file.

Another option is to just use something like zkconf to generate all this for you: http://bit.ly/aQP9Yi

Upvotes: 1

Maurício Linhares
Maurício Linhares

Reputation: 40333

And the issue was that I had an even number of nodes, you need an odd number of nodes to be able to run an election (obviously). The documentation should be updated to cover that, since the basic example shows exactly 2 servers being configured.

Upvotes: 1

Related Questions