ZooKeeper cluster configuration¶
A ZooKeeper cluster configuration enables the deployment of a multi-server setup, which provides high availability and reliability compared to a single-instance deployment.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
Core Configuration Parameters¶
The primary configuration is defined in the zoo.cfg file.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
- tickTime: Defines the basic time unit (in milliseconds) used by ZooKeeper for heartbeats and timeouts.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
- dataDir: Specifies the directory where the snapshot and database files are stored.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
- clientPort: The port on which the server listens for client connections (default is 2181).^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
- initLimit: The time limit (in ticks) for followers to connect to and sync with the leader during the initial startup phase.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
- syncLimit: The time limit (in ticks) for followers to sync with the leader after the initial connection has been made.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
Server Definition¶
Each server in the cluster must be listed in the zoo.cfg file with a specific format to facilitate communication between nodes.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
The syntax for defining a server is:
server.X=hostname:peerPort:leaderPort
- X: The unique server ID (an integer).
- hostname: The DNS name or IP address of the server.
- peerPort: The port used for peer-to-peer communication between ZooKeeper servers (e.g., 2888).
- leaderPort: The port used for leader election (e.g., 3888).^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
Example Configuration¶
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
The myid File¶
In addition to the zoo.cfg file, each server node requires a file named myid to be created in its specific dataDir.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md] This file must contain only the server ID (corresponding to the X in server.X) on a single line.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md] For example, for server.1, the myid file in /var/lib/zookeeper/myid (or the configured dataDir) would contain the text 1.^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]
Sources¶
^[600-developer__big-data__zookpeeper__zookpeeeper-01.md]