How to install ZooKeeper on Elementary OS Latest
ZooKeeper is a distributed coordination service that helps manage distributed systems. It is used to build reliable distributed systems and ensures that the different nodes in the system can communicate with each other.
In this tutorial, we will guide you through the steps to install ZooKeeper on Elementary OS Latest.
Prerequisites
- Elementary OS Latest installed on your computer
- Basic understanding of the terminal commands
Step 1 - Install Java
Before installing ZooKeeper, ensure that you have Java installed on your system. To install it, run the following command:
sudo apt-get install default-jdk
Step 2 - Download and extract ZooKeeper
- Visit the ZooKeeper website and download the latest stable version.
- Extract the downloaded file to the
/optdirectory. You can do this using the following command:
sudo tar -xvf zookeeper-3.6.3.tar.gz -C /opt
- Rename the extracted directory to
zookeeperby running the following command:
sudo mv /opt/zookeeper-3.6.3 /opt/zookeeper
Step 3 - Configure ZooKeeper
- Navigate to the
zookeeper/confdirectory:
cd /opt/zookeeper/conf
- Copy the sample
zoo_sample.cfgfile to a new file namedzoo.cfg:
sudo cp zoo_sample.cfg zoo.cfg
- Edit the
zoo.cfgfile using the text editor of your choice. You will need to provide the list of servers in your ZooKeeper instance. For example:
tickTime=2000
dataDir=/opt/zookeeper/data
clientPort=2181
server.1=192.168.0.1:2888:3888
server.2=192.168.0.2:2888:3888
server.3=192.168.0.3:2888:3888
Replace 192.168.0.1 with the IP address of your first ZooKeeper server; 192.168.0.2 with the IP address of your second server, and so on.
Step 4 - Start ZooKeeper
- Navigate to the
zookeeperdirectory:
cd /opt/zookeeper
- Start the ZooKeeper server using the following command:
sudo ./bin/zkServer.sh start
You should see output similar to the following:
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Step 5 - Verify the installation
To verify the installation, you can use the client utility that comes with ZooKeeper:
./bin/zkCli.sh
You should see output similar to the following:
Connecting to localhost:2181
2021-11-02 14:33:40,844 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.6.3-8c479feea0ffdb2a0c54f9f8eacdf9a1e15a68d4, built on 10/25/2021 06:42 GMT
Welcome to ZooKeeper!
2021-11-02 14:33:40,927 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-11-02 14:33:40,962 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1052] - Socket connection established, initiating session, client: /127.0.0.1:40060, server: localhost/127.0.0.1:2181
JLine support is enabled
[zk: localhost:2181(CONNECTED) 0]
Conclusion
That's it! You have successfully installed and configured ZooKeeper on your Elementary OS Latest. You can now use it to build reliable distributed systems.