zoo_sample.cfg文件改爲zoo.cfghtml
# 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. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/root/zkcluster/3001/data dataLogDir=/root/zkcluster/3001/logs # the port at which the clients will connect clientPort=3001 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=6 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=192.168.161.134:2888:3888 server.2=192.168.161.135:2889:3889 server.3=192.168.161.136:2890:3890
server.A=B:C:D:其中 A 是一個數字,表示這個是第幾號服務器;B 是這個服務器的 ip 地址;C 表示這個服務器與集羣中的 Leader 服務器交換信息的端口;D 表示萬一集羣中的 Leader 服務器掛了,須要一個端口來從新進行選舉,選出一個新的 Leader,而這個端口就是用來執行選舉時服務器相互通訊的端口。apache
能夠用命令看下哪一個server是leader,哪些是follower服務器
[root@localhost bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zkcluster/3001/bin/../conf/zoo.cfg Mode: follower [root@localhost bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zkcluster/3002/bin/../conf/zoo.cfg Mode: leader [root@localhost bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /root/zkcluster/3003/bin/../conf/zoo.cfg Mode: follower