Install and Configure Apache Zookeeper On Linux

Install and Configure Apache Zookeeper On CentOS 8

We can install and configure apache zookeeper on Linux using the source code. This is a service for distributed systems that offers hierarchy key-value stores that are used to provide distributed configuration service, synchronization services, and naming registry for large distributed systems.

First of all, we need to install Java 8 before installing the Zookeeper on CentOS 8. so

[root@localhost ~]# yum install java-1.8* -y

you can find the java location using whereis java command on Linux. we will set the path for Java HOME and JRE. 

[root@localhost ~]# ls /usr/lib/jvm/java-1.8.0-openjdk
[root@localhost ~]# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
[root@localhost ~]# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre/

Check Out: How To Install Revival Theme On Ubuntu and Linux Mint

Set the Path and check the java version installed. 

[root@localhost ~]# export PATH=$JAVA_HOME/bin:/usr/lib/jvm/java-1.8.0-openjdk/jre/bin/
[root@localhost ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

We have to download the Apache Zookeeper and extract it into the /opt directory.

[root@localhost ~]# tar -xvf apache-zookeeper-3.6.0.tar.gz -C /opt/
[root@localhost ~]# cd /opt/apache-zookeeper-3.6.0

Create a data directory. 

[root@localhost ~]# mkdir -p /opt/data
Once you have created a directory, we will check the owner and group of the Apache
zookeeper folder. if you found nobody is the owner and group.
[root@localhost ~]# ls -ld /opt/apache-zookeeper-3.6.0/
drwxrwxr-x. 14 1000 1000 4096 Feb 25 09:36 /opt/apache-zookeeper-3.6.0/
[root@localhost ~]# grep zookeeper /etc/passwd

Check Out: How To Install and Configure Tor Browser On Ubuntu

We checked apache zookeeper doesn't have any owner. So, we will create a user and
assign it to the apache zookeeper folder. 
[root@localhost ~]# useradd zookeeper
[root@localhost ~]# chown -R zookeeper:zookeeper /opt/apache-zookeeper-3.6.0/
[root@localhost ~]# ls -ld /opt/apache-zookeeper-3.6.0/
drwxrwxr-x. 14 zookeeper zookeeper 4096 Feb 25 09:36 /opt/apache-zookeeper-3.6.0/

Create a backup of the default zookeeper configuration file. 

[root@localhost ~]# cd /opt/apache-zookeeper-3.6.0/conf/
[root@localhost conf]# ls
configuration.xsl zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo_sample.cfg-back

Open the configuration file to make changes and add the following parameter if it doesn’t exist. 

[root@localhost conf]# mv zoo_sample.cfg zoo.cfg
[root@localhost conf]# vim zoo.cfg

if require, We have to open the following ports for zookeepers in the firewall rules.

  1. Port 2181= Client connections
  2. Port 2888= followers connections
  3. if you require, Port 3888= for other server connections during the leader election phase. 

Check Out: Top 9 rm Useful Command With Examples On Linux

Start the service using the shell script in /bin/ directory. 

[root@localhost bin]# ./ start
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Create a service for Zookeeper and change the path according to your setup. 

[root@localhost ~]# vim /usr/lib/systemd/system/zookeeper.service
Description=Zookeeper Service

ExecStart=/opt/apache-zookeeper-3.6.0/bin/ start
ExecStop=/opt/apache-zookeeper-3.6.0/bin/ stop
SuccessExitStatus=130 143


Now run the following commands to start the service. 

[root@localhost data]# chown zookeeper:zookeeper
[root@localhost data]# chmod +x
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable zookeeper 
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/zookeeper.service
[root@localhost ~]# systemctl start zookeeper 
[root@localhost ~]# systemctl status zookeeper
● zookeeper.service - Zookeeper Service
Loaded: loaded (/usr/lib/systemd/system/zookeeper.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-04-23 08:52:30 EDT; 3ms ago
Main PID: 40899 (systemd)
Tasks: 0 (limit: 4912)
Memory: 0B
CGroup: /system.slice/zookeeper.service
└─40899 /usr/lib/systemd/systemd --system --deserialize 25

Check Out: Top 13 CP Command Useful Examples For Beginner On Linux

Now you will be connected to the server and will see this message.

[root@localhost bin]# ./
Connecting to localhost:2181
Welcome to ZooKeeper!
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]

Once you’re connected and perform your operations and you can stop the service.

[root@localhost bin]# ./ stop

You’re done install apache zookeeper linux

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment