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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  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.

Gaurav Garg user avatar by
Gaurav Garg
·
May. 27, 18 · Tutorial
Like (3)
Save
Tweet
Share
42.78K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Popular on DZone

  • Beginners’ Guide to Run a Linux Server Securely
  • A Beginner's Guide to Back-End Development
  • Last Chance To Take the DZone 2023 DevOps Survey and Win $250! [Closes on 1/25 at 8 AM]
  • How To Validate Three Common Document Types in Python

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: