Operations 12 min read

Install, Visualize, and Use ZooKeeper as a Spring Cloud Registry

This guide walks you through installing ZooKeeper on Windows and Linux, managing it with the PrettyZoo GUI, and configuring it as a Spring Cloud service registry, covering node types, command‑line operations, and practical examples of service registration and discovery.

macrozheng
macrozheng
macrozheng
Install, Visualize, and Use ZooKeeper as a Spring Cloud Registry
ZooKeeper is a top‑level open‑source distributed coordination project widely used by Dubbo, Kafka and other projects.

Introduction

ZooKeeper is a distributed coordination framework that provides consistency services for distributed systems. It was originally developed by Yahoo, later donated to the Apache Foundation, and is now a top‑level Apache project with over 9.5k stars on GitHub.

Distributed Coordination

Understanding ZooKeeper starts with the concept of distributed coordination. In a microservice system, many service instances exist; a registry coordinates service names and instance IPs, and ZooKeeper can act as this coordinator.

Installation

ZooKeeper can be installed on both Windows and Linux.

Windows Installation

Download the ZooKeeper binary package from https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz .

Extract it to a chosen directory.

Create a configuration file conf/zoo.cfg with the following content:

# Set tick time in milliseconds
tickTime=2000
# Directory for snapshot data
dataDir=I:/developer/env/apache-zookeeper-3.7.0-bin/data
# Client connection port
clientPort=2181

Start the service from the bin directory: zkServer.cmd When the service starts successfully, the console displays startup information.

Linux Installation

Pull the Docker image: docker pull zookeeper:3.7.0 Create a configuration directory and file zoo.cfg:

mkdir -p /mydata/zookeeper/conf/
cd /mydata/zookeeper/conf/
touch zoo.cfg

Write the same configuration as above into zoo.cfg:

# Set tick time in milliseconds
tickTime=2000
# Directory for snapshot data
dataDir=/tmp/zookeeper
# Client connection port
clientPort=2181

Run the ZooKeeper container:

docker run -p 2181:2181 --name zookeeper \
-v /mydata/zookeeper/conf/zoo.cfg:/conf/zoo.cfg \
-d zookeeper:3.7.0

Command‑line Operations

Use the zkCli tool to interact with ZooKeeper.

Connect: zkCli.cmd -server 127.0.0.1:2181 List root znodes:

[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]

Create a znode /zk_test with data my_data:

[zk: 127.0.0.1:2181(CONNECTED) 2] create /zk_test my_data
Created /zk_test

Retrieve data:

[zk: 127.0.0.1:2181(CONNECTED) 4] get /zk_test
my_data

Update data:

[zk: 127.0.0.1:2181(CONNECTED) 5] set /zk_test test_data
[zk: 127.0.0.1:2181(CONNECTED) 6] get /zk_test
test_data

Delete the znode:

[zk: 127.0.0.1:2181(CONNECTED) 7] delete /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 8] ls /
[zookeeper]

Visual Management

PrettyZoo is a JavaFX‑based graphical client for ZooKeeper.

Download PrettyZoo from GitHub releases and install.

Create a connection to the ZooKeeper server; PrettyZoo supports SSH tunneling.

The UI shows the hierarchical data stored in ZooKeeper.

Right‑click a node to create or delete znodes, eliminating the need for command‑line operations.

PrettyZoo also provides a built‑in command‑line tab for advanced usage.

Node Types

ZooKeeper nodes (znodes) have four main types:

Persistent – remains after the session ends.

Persistent Sequential – persistent with an auto‑incremented suffix.

Ephemeral – removed when the session that created it closes.

Ephemeral Sequential – ephemeral with an auto‑incremented suffix.

When creating nodes via the CLI, the -s option adds the sequential flag and -e adds the ephemeral flag. Example:

# Create a persistent sequential node
create -s /test/seq segText
# Create an ephemeral node
create -e /test/tmp tmpText
# Create an ephemeral sequential node
create -s -e /test/seqTmp setTmpText

Using ZooKeeper as a Service Registry

ZooKeeper follows the CP model of the CAP theorem, making it suitable for service registration.

Add the Spring Cloud ZooKeeper discovery starter to pom.xml:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>

Configure application.yml:

spring:
  cloud:
    zookeeper:
      # ZooKeeper connection string
      connect-string: localhost:2181
      discovery:
        # Register services
        register: true
        # Use IP address instead of hostname
        prefer-ip-address: true

In a sample Spring Cloud project, two services ( zookeeper-ribbon-service and zookeeper-user-service) register with ZooKeeper. Using PrettyZoo you can see the service names, IPs, and ports stored as temporary nodes.

When a service shuts down, its temporary node is automatically removed, ensuring high availability.

Summary

This guide covered ZooKeeper installation on Windows and Linux, management with PrettyZoo, command‑line operations, node types, and how to use ZooKeeper as a Spring Cloud service registry, laying a foundation for further exploration such as distributed locks, leader election, or unique ID generation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Spring CloudDistributed CoordinationPrettyZoo
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.