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

  1. Download Apache ZooKeeper
    Download Apache ZooKeeper "3.9.3": http://zookeeper.apache.org/releases.html
  2. Configure a ZooKeeper Cluster on the same host
    Extract the content of "apache-zookeeper-3.9.3-bin.tar.gz" file to three locations of your choice:
    ► /opt/zookeeper-i1
    ► /opt/zookeeper-i2
    ► /opt/zookeeper-i3

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

    $ cp -r /opt/apache-zookeeper-3.9.3-bin/ /opt/zookeeper-i1/
    $ cp -r /opt/apache-zookeeper-3.9.3-bin/ /opt/zookeeper-i2/
    $ mv /opt/apache-zookeeper-3.9.3-bin/ /opt/zookeeper-i3/

    Change the folders permissions (if needed):
    $ chmod -R 755 /opt/zookeeper-i1/
    $ chmod -R 755 /opt/zookeeper-i2/
    $ chmod -R 755 /opt/zookeeper-i3/

    $ sudo chown -R mtitek:mtitek /opt/zookeeper-i1/
    $ sudo chown -R mtitek:mtitek /opt/zookeeper-i2/
    $ sudo chown -R mtitek:mtitek /opt/zookeeper-i3/

    You should replace mtitek:mtitek with your actual user/group names.

    First, for each ZooKeeper binary distribution ("zookeeper-i1", "zookeeper-i2", "zookeeper-i3"), you need to do the following instructions:
    • Create the folder "data":
      $ mkdir /opt/zookeeper-i1/data
      $ mkdir /opt/zookeeper-i2/data
      $ mkdir /opt/zookeeper-i3/data

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

    • Create the log folder "logs":
      $ mkdir /opt/zookeeper-i1/logs
      $ mkdir /opt/zookeeper-i2/logs
      $ mkdir /opt/zookeeper-i3/logs

    • Copy the file "conf/zoo_sample.cfg" to "conf/zoo.cfg":
      $ cp /opt/zookeeper-i1/conf/zoo_sample.cfg /opt/zookeeper-i1/conf/zoo.cfg
      $ cp /opt/zookeeper-i2/conf/zoo_sample.cfg /opt/zookeeper-i2/conf/zoo.cfg
      $ cp /opt/zookeeper-i3/conf/zoo_sample.cfg /opt/zookeeper-i3/conf/zoo.cfg

    • Initialize the server id for each ZooKeeper instance:
      $ echo "1" > /opt/zookeeper-i1/data/myid
      $ echo "2" > /opt/zookeeper-i2/data/myid
      $ echo "3" > /opt/zookeeper-i3/data/myid

    For each ZooKeeper binary distribution you will need to modify the "conf/zoo.cfg" file:
    • Modify the properties "dataDir" and "dataLogDir":

      • First instance ("/opt/zookeeper-i1/conf/zoo.cfg"):
        dataDir=/opt/zookeeper-i1/data
        dataLogDir=/opt/zookeeper-i1/data-log

      • Second instance ("/opt/zookeeper-i1/conf/zoo.cfg"):
        dataDir=/opt/zookeeper-i2/data
        dataLogDir=/opt/zookeeper-i2/data-log

      • Third instance ("/opt/zookeeper-i1/conf/zoo.cfg"):
        dataDir=/opt/zookeeper-i3/data
        dataLogDir=/opt/zookeeper-i3/data-log

    • Add a static configuration for each ZooKeeper instance:
      server.1=localhost:2888:3888:participant;0.0.0.0:2181
      server.2=localhost:2889:3889:participant;0.0.0.0:2182
      server.3=localhost:2890:3890:participant;0.0.0.0:2183

    • 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).

    • Because the default port is 8080 for the Jetty embedded server, You need to add the property "admin.serverPort" to override the default value. This allow each instance to have its unique port for AdminServer http interface.
      Reminder: this step is needed because we are configuring multiple ZooKeeper instances on the same host.

      • First instance ("/opt/zookeeper-i1/conf/zoo.cfg"):
        admin.serverPort=8081

      • Second instance ("/opt/zookeeper-i2/conf/zoo.cfg"):
        admin.serverPort=8082

      • Third instance ("/opt/zookeeper-i3/conf/zoo.cfg"):
        admin.serverPort=8083

    Example: ZooKeeper configuration file "zoo.cfg"

    /opt/zookeeper-i1/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-i1/data
    
    # The directory the transaction log of updates is stored.
    dataLogDir=/opt/zookeeper-i1/data-log
    
    # the port at which the clients will connect: 2181, 2182, 2183
    # the port address at which the clients will connect: 0.0.0.0
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    server.3=localhost:2890:3890:participant;0.0.0.0:2183
    
    # Jetty AdminServer http port
    admin.serverPort=8081

    /opt/zookeeper-i2/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-i2/data
    
    # The directory the transaction log of updates is stored.
    dataLogDir=/opt/zookeeper-i2/data-log
    
    # the port at which the clients will connect: 2181, 2182, 2183
    # the port address at which the clients will connect: 0.0.0.0
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    server.3=localhost:2890:3890:participant;0.0.0.0:2183
    
    # Jetty AdminServer http port
    admin.serverPort=8082

    /opt/zookeeper-i3/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-i3/data
    
    # The directory the transaction log of updates is stored.
    dataLogDir=/opt/zookeeper-i3/data-log
    
    # the port at which the clients will connect: 2181, 2182, 2183
    # the port address at which the clients will connect: 0.0.0.0
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    server.3=localhost:2890:3890:participant;0.0.0.0:2183
    
    # Jetty AdminServer http port
    admin.serverPort=8083
  3. Start/Stop ZooKeeper
    To start ZooKeeper instances:
    $ /opt/zookeeper-i1/bin/zkServer.sh start
    
    $ /opt/zookeeper-i2/bin/zkServer.sh start
    
    $ /opt/zookeeper-i3/bin/zkServer.sh start

    To stop ZooKeeper instances:
    $ /opt/zookeeper-i1/bin/zkServer.sh stop
    
    $ /opt/zookeeper-i2/bin/zkServer.sh stop
    
    $ /opt/zookeeper-i3/bin/zkServer.sh stop
© 2025  mtitek