To configure ZooKeeper instances that are parts of a ZooKeeper ensemble you can configure the file "
zoo.cfg
" of each instance to list all instances of the ZooKeeper ensemble.
For example, If a ZooKeeper cluster has 3 instances of ZooKeeper installed on
3
hosts: "
zkhost1
", "
zkhost2
", and "
zkhost3
".
For each instance, we need to modify the file "
zoo.cfg
" to add the following:
server.1=zkhost1:2888:3888:participant;0.0.0.0:2181
server.2=zkhost2:2888:3888:participant;0.0.0.0:2181
server.3=zkhost3:2888:3888:participant;0.0.0.0:2181
Example: ZooKeeper configuration file "zoo.cfg
" of the host "zkhost1
"
# 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 port at which the clients will connect: 2181
# the port address at which the clients will connect: 0.0.0.0
server.1=zkhost1:2888:3888:participant;0.0.0.0:2181
server.2=zkhost2:2888:3888:participant;0.0.0.0:2181
server.3=zkhost3:2888:3888:participant;0.0.0.0:2181
# The directory where the snapshot data is stored.
dataDir=/opt/zookeeper/data/
# The directory the transaction log of updates is stored.
dataLogDir=/opt/zookeeper/data-log/
The
initLimit value designates the amount of time to allow a follower to connect with the leader.
The
syncLimit value limits the amount of time a follower can not be synchronized with the leader.
Both
initLimit and
syncLimit are calculated based on the
tickTime value:
- initLimit = initLimit * tickTime
- syncLimit = syncLimit * tickTime
In the example above,
the
tickTime value was set to 2000 (ms),
the
initLimit value was set to 10,
and the
syncLimit value was set to 5.
- So, the real value of
initLimit is 10 × 2000 ms = 20 seconds.
- and, the real value of
syncLimit is 5 × 2000 ms = 10 seconds.
Note that in previous versions of ZooKeeper, when you start ZooKeeper,
the static configuration of the zookeeper ensemble will be copied to a new file
and a new parameter ("
dynamicConfigFile
") will be added to the file "
zoo.cfg
" to reference this new file:
dynamicConfigFile=/opt/zookeeper/conf/zoo.cfg.dynamic.100000000
Note that if you use a client to add/remove instances from the ZooKeeper cluster,
then the configuration of the zookeeper ensemble will be copied to a new file as explained above.