DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • One Query, Four GPUs: Tracing a Distributed Training Stall Across Nodes
  • Implementing Budget Policies and Budget Limits on Databricks
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot

Trending

  • When RabbitMQ Accepts a Message but Does Not Route It to a Queue
  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views
  • LangChainGo vs Genkit Go: Where Genkit Shines
  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Setup Zookeeper Cluster

How to Setup Zookeeper Cluster

In this article, a software engineer will discuss how to setup a Zookeeper cluster with 3 nodes, giving you the knowledge to create as many nodes as you need.

By 
Gaurav Garg
·
May. 27, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
45.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In my previous article, I discussed how to set up Zookeeper with a single node. For better reliability and high availability of the Zookeeper service, we should set up Zookeeper in cluster mode. In this article, I will discuss how to setup a Zookeeper cluster with 3 nodes. Zookeeper clusters are also called Zookeeper ensembles. At the end of this article, you will be able to set up an ensemble with as many nodes as you desire. 

Download Zookeeper from here.

Extract the zip file. Make two extra copies of the extracted folder. Add the suffixes _1,_2,_3 to these folders' names. So if your extracted folder was zookeeper-3.4.12,now you will have three folders with the names zookeeper-3.4.12_1, zookeeper-3.4.12_2, zookeeper-3.4.12_3. 

  1. Go to the zookeeper-3.4.12_1 directory.  

  2. Create two folders with the names data and logs inside Zookeeper's home directory.

  3. Execute the command  echo "1" > data/myid. This is the server id in the ensemble. The id must be unique within the ensemble and should have a value between 1 and 255.

  4. Go to the conf folder and change the name of the zoo_sample.cfg file to zoo.cfg.

  5. Change dataDir with the full path of the data folder that we created in the above step.

  6. Set the clientPort to 2181.

  7. Paste the below lines into the zoo.cfg file.

server.1=localhost:2891:3881
#1 is the id that we put in myid file.
server.2=localhost:2892:3882
#2 is the id that we will put in myid file of second node.
server.3=localhost:2893:3883
#3 is the id that we will put in myid file of third node.

Zookeeper will use these ports (2891, etc.) to connect the individual follower nodes to the leader nodes. The other ports (3881, etc.) are used for leader election in the ensemble.

Our configuration is ready for the first node. For the other two folders or nodes, perform the same steps as mentioned above with the following changes.

  • In step 3, change the command to echo "2" > data/myid and echo "3" > data/myid respectively.

  • In step 6, change the port to 2182 and 2183, respectively.

Now our configuration is ready. Go to the home directory of each folder and the execute command:

 java -cp zookeeper-3.4.12.jar:lib/log4j-1.2.17.jar:lib/slf4j-log4j12-1.7.25.jar:lib/slf4j-api-1.7.25.jar:conf org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg >> logs/zookeeper.log & 

Check the logs to see whether your cluster is ready or not.

Conclusion  

We discussed how to set up an ensemble with 3 nodes. Now you can create an ensemble with as many nodes as you want by making a few changes.

cluster

Opinions expressed by DZone contributors are their own.

Related

  • Node and Capacity Spillover: What Happens When Kubernetes Runs Out of Room
  • One Query, Four GPUs: Tracing a Distributed Training Stall Across Nodes
  • Implementing Budget Policies and Budget Limits on Databricks
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook