在zookeeper-3.3.6使用分布式安装:
单机版分布式安装
这时需要配置的是conf目录下的zoo.cfg文件:
配置文件内容(这里模拟了5个节点,其中三个节点为participant,而另外两个为observer):
# 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=/home/qzhong/zookeeper0/data
dataLogDir=/home/qzhong/zookeeper0/log
# the port at which the clients will connect
clientPort=2180
peerType=participant
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
server.3=127.0.0.1:8883:7773
server.4=127.0.0.1:8884:7774
# 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=/home/qzhong/zookeeper4/data
dataLogDir=/home/qzhong/zookeeper4/log
# the port at which the clients will connect
clientPort=2184
peerType=observer
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
server.3=127.0.0.1:8883:7773
server.4=127.0.0.1:8884:7774
在单机上运行分布式遇到的问题:
运行客户端能运行正常,但是观看日志文件,会发现日志文件有问题。关于选举实例变量epoch会出现你无法理解的数值(观看这些debug信息,可以通过设置conf/log4j.properties,设置info为debug,这样就能看到这些信息,仔细观看日志文件会发现一些异常在单机版运行分布式zookeeper,这个问题可能跟jvm相关)。
多台计算机上运行分布式zookeeper(切记zookeeper配置数量为奇数,这样才能满足达到quorum的要求,或者在zoo.cfg文件中设置各个zookeeper的组的权重值,而不是只是简单的看数量)
多台计算机上运行zookeeper分布式配置(默认情况下是所有的节点参与leader 选举):
conf/zoo.cfg:
# 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=/home/qzhong/zookeeper/data
dataLogDir=/home/qzhong/zookeeper/log
# the port at which the clients will connect
clientPort=2181
#the default case that this server stand for participant
server.0=qzhong:8880:7770
server.1=node27:8880:7770
server.2=node100:8880:7770