Install JDK
install a jdk into system dirs, so all users can visit
bash
sudo apt install openjdk-17-jdk -y
bash
java -version
Configure JAVA_HOME
bash
sudo open /etc/profile
replace with you own path, pirnt by java command above
bash
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
bash
source /etc/profile
Create ZooKeeper User
bash
sudo adduser --system --no-create-home --group zookeeper
Set Home Directory for User
bash
sudo mkdir /opt/zookeeper
sudo chown zookeeper:zookeeper /opt/zookeeper
Create Data Directory for ZooKeeper
bash
sudo mkdir /var/lib/zookeeper
sudo chown zookeeper:zookeeper /var/lib/zookeeper
Download ZooKeeper Package
bash
cd /tmp
wget https://downloads.apache.org/zookeeper/zookeeper-3.9.3/apache-zookeeper-3.9.3-bin.tar.gz
Extract ZooKeeper to Install Directory
bash
sudo tar -xzf apache-zookeeper-3.9.3-bin.tar.gz -C /opt/zookeeper --strip-components=1
Configure Directory Permission
bash
sudo chown -R zookeeper:zookeeper /opt/zookeeper
Verify Installation Files
this directory should contains folders like bin, conf, lib
bash
ls -l /opt/zookeeper
Configure ZooKeeper
bash
sudo cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg
bash
sudo nano /opt/zookeeper/conf/zoo.cfg
bash
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
maxClientCnxns=60
admin.enableServer=true
admin.serverPort=20001
Create System Service for ZooKeeper
bash
sudo nano /etc/systemd/system/zookeeper.service
bash
[Unit]
Description=Apache ZooKeeper service
Documentation=http://zookeeper.apache.org
Requires=network.target
After=network.target
[Service]
Type=forking
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
ExecReload=/opt/zookeeper/bin/zkServer.sh restart
WorkingDirectory=/opt/zookeeper
[Install]
WantedBy=multi-user.target
bash
sudo systemctl enable zookeeper
bash
sudo systemctl stop zookeeper
sudo systemctl start zookeeper
sudo systemctl status zookeeper
Test ZooKeeper Service
if successful, you will see a ZooKeeper command line prompt
bash
/opt/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
bash
ls /
also, you can launch the admin webpage
bash
http://localhost:20001/commands
Check Startup Failure
if service start up failed, print log to get a check
bash
journalctl -u zookeeper