Blog
This blog provides a step-by-step guide on installing and configuring ZooKeeper on Linux, macOS, and Windows. It covers the prerequisites, installation process, key configuration settings in the zoo.cfg file, and how to test ZooKeeper using the CLI. The article also includes tips for optimal performance.
Zookeeper is a distributed coordination service for distributed applications, ensuring coordination and synchronization across multiple nodes. Simply, it provides a way for applications to coordinate with each other in a reliable and fault-tolerant way. However, setting it up can be a daunting task, especially for beginners. So, we are here with a step-by-step guide that simplifies the installation process, making it accessible for developers and system administrators.
You will also learn about prerequisite steps, installation steps, and crucial configuration settings in the zoo.cfg file. Moreover, this guide also includes testing Zookeeper using the Command-line interface (CLI) and further tips.
Installing Apache ZooKeeper on different platforms, including macOS, Windows, and Linux, requires platform-specific approaches. Differences in package management, scripting, and file systems are the primary reasons behind the varying approaches to installation.
macOS uses Homebrew for a streamlined installation with brew install ZooKeeper.
Ubuntu combines apt for Java and manual tarball extraction with zkServer.sh.
And Windows relies on manual tarball setup, JAVA_HOME configuration, and zkServer.cmd.
All platforms, however, need Java, a zoo.cfg file, and zkCli to verify the connection to 127.0.0.1:2181.
To install ZooKeeper on Linux, you can follow these steps:
bashCopyEditsudo apt update
sudo apt upgrade -y
ZooKeeper requires Java to run. You can install OpenJDK:
bashCopyEditsudo apt install default-jdk -y
Verify Java is installed:
bashCopyEditjava -version
bashCopyEditsudo useradd zookeeper -m
Find the latest version at: https://zookeeper.apache.org/releases.html
bashCopyEditcd /opt
sudo wget https://downloads.apache.org/zookeeper/zookeeper-3.9.2/apache-zookeeper-3.9.2-bin.tar.gz
sudo tar -xzf apache-zookeeper-3.9.2-bin.tar.gz
sudo mv apache-zookeeper-3.9.2-bin zookeeper
sudo chown -R zookeeper:zookeeper /opt/zookeeper
Create a Data Directory:
bashCopyEditsudo mkdir -p /var/lib/zookeeper
sudo chown zookeeper:zookeeper /var/lib/zookeeper
Create Configuration File:
bashCopyEditsudo nano /opt/zookeeper/conf/zoo.cfg
Paste the following minimal config:
iniCopyEdittickTime=2000 dataDir=/var/lib/zookeeperclientPort=2181 initLimit=5 syncLimit=2
Save and exit (Ctrl+O, then Ctrl+X).
Switch to the zookeeper user:
bashCopyEditsudo su - zookeepercd /opt/zookeeper
bin/zkServer.sh start
To check status:
bashCopyEditbin/zkServer.sh status
To stop ZooKeeper:
bashCopyEditbin/zkServer.sh stop
bashCopyEditsudo nano /etc/systemd/system/zookeeper.service
Paste:
iniCopyEdit[Unit] Description=Apache ZooKeeper ServerAfter=network.target
[Service] Type=simpleUser=zookeeperExecStart=/opt/zookeeper/bin/zkServer.sh start-foregroundExecStop=/opt/zookeeper/bin/zkServer.sh stopRestart=on-abnormal
[Install] WantedBy=multi-user.target
Enable and start:
bashCopyEditsudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable zookeeper
sudo systemctl start zookeeper
Now your macOS is ready for ZooKeeper installation.
Homebrew is a package manager for macOS. Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install zookeeper
This will install ZooKeeper and its dependencies.
You can start ZooKeeper using the built-in configuration:
zkServer start
To stop ZooKeeper:
zkServer stop
To check the status:
zkServer status
brew services start zookeeper
This will keep ZooKeeper running in the background across reboots.
You can verify ZooKeeper is running by connecting to it via the CLI:
zkCli
Follow the ensuing steps to run Zookeeper on Windows;
bashCopyEditjava -version
If not recognized, add Java's bin folder to your system's Environment Variables(Path.)
propertiesCopyEdittickTime=2000
dataDir=C:/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2
bashCopyEditmkdir C:\zookeeper\data
bashCopyEditcd path\to\zookeeper-3.8.4-bin\bin
bashCopyEditzkServer.cmd
You should see Mode: standalone at the end, meaning it iss running.
bashCopyEditzkCli.cmd
bashCopyEditcreate /test "hello"get /test
The conf/zoo.cfg file contains the configuration settings for your ZooKeeper cluster. These settings include the following:
For more information on the configuration settings, please refer to the ZooKeeper documentation: https://zookeeper.apache.org/doc/r3.1.2/zookeeperStarted.html
Once you have installed and configured ZooKeeper, you can test it by connecting to it using the ZooKeeper CLI. The ZooKeeper CLI is a command-line tool that allows you to interact with ZooKeeper.
Run the following command to start;
bin/zkCli.sh start
Next, you will see the following standard response:
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Now, you can test it by connecting to it using the ZooKeeper CLI. The ZooKeeper CLI is a command-line tool that allows you to interact with ZooKeeper.
Upon connection, you should see a prompt indicating a successful connection to 127.0.0.1:2181.
In this blog, we went through the step-by-step guide for installing Zookeeper on Windows, Linux, and macOS. This will help you get started with Zookeeper, no matter the operating system you are using. Here, we also discussed some additional tips for securing the ZooKeeper setup. Hope this helps!
One-stop solution for next-gen tech.