• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
ZooKeeper | Install and configure a ZooKeeper Standalone Server
  1. Download and Install Apache ZooKeeper
  2. ZooKeeper Configuration
  3. Start/Stop ZooKeeper

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

    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. ZooKeeper Configuration
    • 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

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

    • Define the property "dataLogDir" in the file "/opt/zookeeper/conf/zoo.cfg": dataLogDir=/opt/zookeeper/data-log

    Make sure that the directories and the files are created and updated using the user that will run ZooKeeper (you can also use: sudo -u mtitek mkdir data).

    Example: ZooKeeper configuration file "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 port at which the clients will connect.
    clientPort=2181
    
    # The port address at which the clients will connect.
    clientPortAddress=0.0.0.0
    
    # 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

    Notes:
    • If you run ZooKeeper in a cluster mode, the clientPort and clientPortAddress configuration parameters should be part of the ZooKeeper instances configuration (see Installation - ZooKeeper Cluster).

    • (On Windows) if not already the case, you have to double-quote the path "%JAVA_HOME%"\bin\java.exe in the file "%ZK_HOME%\bin\zkEnv.cmd"

    • (On Windows) if not already the case, you have to double-quote the path "%JAVA%" in the file "%ZK_HOME%\bin\zkServer.cmd"

    Other configuration you might want to setup in file "zoo.cfg"
    # The maximum number of client connections. Increase this if you need to handle more clients.
    maxClientCnxns=60
    
    # The number of snapshots to retain in dataDir.
    autopurge.snapRetainCount=3
    
    # Purge task interval in hours. Set to "0" to disable auto purge feature.
    autopurge.purgeInterval=1

    You can optionally configure the JAVA_HOME environment variable:
    $ vi /opt/zookeeper/conf/java.env
    export JAVA_HOME=/opt/jdk-23.0.2
  3. Start/Stop ZooKeeper
    Start ZooKeeper:
    $ /opt/zookeeper/bin/zkServer.sh start

    Stop ZooKeeper:
    $ /opt/zookeeper/bin/zkServer.sh stop

    Notes:
    • By default ZooKeeper will try to use the configuration file found in "/opt/zookeeper/conf/zoo.cfg"

    • You can specify a custom configuration file by posting its path after the "start" and "stop" parameters:
      $ /opt/zookeeper/bin/zkServer.sh start "/opt/zookeeper/conf/zoo_custom.cfg"
      $ /opt/zookeeper/bin/zkServer.sh stop "/opt/zookeeper/conf/zoo_custom.cfg"

    • You can specify a custom configuration folder by using the option "--config" before the "start" and "stop" parameters:
      $ /opt/zookeeper/bin/zkServer.sh --config "/opt/zookeeper/conf_custom" start
      $ /opt/zookeeper/bin/zkServer.sh --config "/opt/zookeeper/conf_custom" stop

© 2025  mtitek