How To Setup a Zookeeper Cluster – Beginners Guide

Zookeeper is a distributed coordination tool which can be used for various distributed workloads. In this article, we have explained the necessary steps to install and configure zookeeper cluster with a definite quorum.

Setup a Zookeeper Cluster

Prerequisites

1. Three VM’s. (Forms a quorum). For high availability cluster, you can go with any odd number above 3. For example, if you set up 5 servers, the cluster can handle two failed nodes and so on.

2. VM’s with inbound connections on ports 2888, 3888 and 2181. If IPtables is enabled, make sure you enable the specified ports because zookeeper communication happens through these ports.

Note: If you are using AWS or any other cloud provider, apart from server level inbound connections, make sure you enable the security groups or endpoints for the zookeeper ports.

Install and Configure Zookeeper

You need to perform the following steps in all the three VM’s.

1. Update your server.

2. Install Java if is not installed.

3. Download zookeeper. b If you wish to choose another version, you can get the download links from here.

4. Untar the application to /opt folder

5. Rename the zookeeper app directory

6. Create a zoo.cfg file in /opt/zookeeper/conf directory with the configurations shown below.

READ  Kubernetes Ingress Tutorial For Beginners

In the above code, server 1, 2 and 3 represent our three zookeeper servers. You need to replace the Zookeeper_IP with relevant IP or resolvable hostnames.

7. Create a zookeeper directory in the lib folder. Thar will be zookeepers data directory as mentioned in the zoo.cfg file.

8. Create a file name myid in /var/lib/zookeeper/ directory .

9. Each zookeeper server should have a unique number in the myid file. For example, server 1 will have value 1, server 2 will have value 2 and so on.

server 1

server 2

server 1

Configuring Zookeeper as a Service

Zookeeper can be started and stopped using the scripts. But it is good to run it as a service to manage it in an elegant way.

1. Open zkServer.zh file for editing.

2. Add the following below the shebang “#!/usr/bin/env bash” to add zookeeper to the system start up.

3. Find a line which says “# use POSTIX┬áinterface, symlink is followed automatically”. Replace the existing variables after that line with the following.

READ  Getting Started With Docker : Working With Containers

4. Now, create a symlink for the zookeeper service.

5. Add zookeeper to the boot menu.

6. Now, Restart all the servers.

7. Once restarted, you can manage zookeeper servers using the following commands.

8. When you check the status, it should produce an output like the following.

out of three servers, one will be in leader mode and other two will be in follower mode.

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.