• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
ZooKeeper | Install and configure a ZooKeeper Cluster on different hosts
  1. Download and Install Apache ZooKeeper
  2. Configure a ZooKeeper Cluster on 3 hosts
  3. Start/Stop ZooKeeper

  1. Download and Install Apache ZooKeeper
    Download Apache ZooKeeper "3.9.3": http://zookeeper.apache.org/releases.html

    In the following, we will install ZooKeeper in 3 different hosts: "zkhost1", "zkhost2", and "zkhost3"

    On each host, extract the file "apache-zookeeper-3.9.3-bin.tar.gz" in the folder you want to install ZooKeeper:
    ► /opt/apache-zookeeper-3.9.3-bin

    $ tar -xf apache-zookeeper-3.9.3-bin.tar.gz -C /opt/

    Optional: Create a symbolic link of the ZooKeeper installation folder:
    $ ln -s /opt/apache-zookeeper-3.9.3-bin/ /opt/zookeeper

    Change the folders permissions (if needed):
    $ chmod -R 755 /opt/apache-zookeeper-3.9.3-bin/
    $ sudo chown -R mtitek:mtitek /opt/apache-zookeeper-3.9.3-bin/
    $ sudo chown -R mtitek:mtitek /opt/zookeeper

    You should replace mtitek:mtitek with your actual user/group names.
  2. Configure a ZooKeeper Cluster on 3 different hosts
    On each host ("zkhost1", "zkhost2", and "zkhost3"), do the following:

    Create the data and logs directories:
    • Create the folder "data": "/opt/zookeeper/data"
      $ mkdir /opt/zookeeper/data

    • Create the folder "data-log": "/opt/zookeeper/data-log"
      $ mkdir /opt/zookeeper/data-log

    • Create the log folder: "/opt/zookeeper/logs"
      $ mkdir /opt/zookeeper/logs

    • Copy the file "/opt/zookeeper/conf/zoo_sample.cfg" to "/opt/zookeeper/conf/zoo.cfg"
      $ cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg

    Initialize the server id for each ZooKeeper instance:
    • First instance ("zkhost1"):
      $ echo "1" > /opt/zookeeper/data/myid

    • Second instance ("zkhost2"):
      $ echo "2" > /opt/zookeeper/data/myid

    • Third instance ("zkhost3"):
      $ echo "3" > /opt/zookeeper/data/myid

    Adjust the configuration file "conf/zoo.cfg":
    • Define the property "dataDir": dataDir=/opt/zookeeper/data

    • Define the property "dataLogDir": dataLogDir=/opt/zookeeper/data-log

    • Add a static configuration for each ZooKeeper instance on the 3 hosts:
      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

    • Remove the properties "clientPort" and "clientPortAddress".
      You should not include these parameters in the ZooKeeper configuration "conf/zoo.cfg" file. They should be part of the ZooKeeper instances configuration (see above).

    Example: ZooKeeper configuration file "zoo.cfg" (/opt/zookeeper/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 data is stored.
    dataDir=/opt/zookeeper/data
    
    # The directory the transaction log of updates is stored.
    dataLogDir=/opt/zookeeper/data-log
    
    # 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
  3. Start/Stop ZooKeeper
    To start ZooKeeper instances, run the following command on each host:
    $ /opt/zookeeper/bin/zkServer.sh start

    To stop ZooKeeper instances, run the following command on each host:
    $ /opt/zookeeper/bin/zkServer.sh stop

© 2025  mtitek