• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
ZooKeeper | ZooKeeper ensemble configuration
  1. ZooKeeper ensemble configuration
  2. Static configuration
  3. Dynamic configuration file

  1. ZooKeeper ensemble configuration
    To configure a ZooKeeper ensemble, you need to configure the file "zoo.cfg" of each instance to contain the list of all instances.
    And each instance must have a "myid" file (under the data directory) that has its ID number (used in the file "zoo.cfg").

    To add a ZooKeeper instance to the ZooKeeper ensemble, you need to add the following parameter to the file "zoo.cfg":

    • <id>: the ZooKeeper instance id.
      Must be an integer, but it's not required to start with 0 or to be sequential.
      Each ZooKeeper instance must have a file in the "dataDir" directory with the name "myid" that must contains its id number.

    • <zk_host_address>: the host name or ip address where the ZooKeeper instance is running

    • <zk_peer_port>: (peer tcp port) is used by peer ZooKeeper instances to communicate with each other.

    • <zk_leader_port>: (leader tcp port) is used for the ZooKeeper leader election.

    • <zk_role>: ZooKeeper instances roles ("participant", "observer").
      The role is optional, and if not specified it defaults to "participant".

    • <zk_client_port_address>: The client port address is optional, and if not specified it defaults to "0.0.0.0".

    • <zk_client_port>: A client port of a ZooKeeper instance is the port on which the ZooKeeper instance accepts client connection requests.

    The ZooKeeper instances use the peer, leader, and client ports to do different type of communications between each other.
    The ZooKeeper clients can use only the client ports to communicate with the ensemble.
  2. Static configuration
    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:

    Example: ZooKeeper configuration file "zoo.cfg" of the host "zkhost1"

    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 initLi⁠mit 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.

    Please 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:

    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.
  3. Dynamic configuration file
    You can configure the file "zoo.cfg" to add a dynamic configuration of the ZooKeeper instances which are parts 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 parameter "dynamicConfigFile" as follow:

    Example: ZooKeeper configuration file "zoo.cfg" of the host "zkhost1"

    The "zoo.cfg.dynamic" file will contain the dynamic configuration of the ZooKeeper ensemble:
© 2025  mtitek