无法让ZooKeeper集群工作,选举从未发生

这是我第一次尝试ZooKeeper,虽然我可以轻松地将它设置为在一台机器上运行,但是让它在两台机器的集群中运行根本不起作用。 我认为这可能是我的configuration有问题,但看起来不像我能find它。

这里是服务器1的日志

这里是服务器2的日志

我的configuration如下两台服务器:

# 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 

任何想法可能是什么问题?

我在运行OpenJDK 7的Ubuntu Linux框中运行ZooKeeper 3.4.5。试图在OpenJDK 6上运行,但仍然遇到同样的问题。

您的配置无效,具体而言

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

如果你在同一个主机上运行两个实例,你需要为每个端口设置不同的端口号,最好是这样的

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

请注意,你应该有相同的服务器。#配置两个服务器的配置文件。

另一个选择是使用像zkconf这样的东西来生成所有这些: http ://bit.ly/aQP9Yi

问题是,我有一个偶数的节点,你需要一个奇数的节点才能进行选举(显然)。 该文档应该更新,以涵盖,因为基本示例显示正好配置了2个服务器。