Zookeeper

How to install and configure Zookeeper, covering local, docker, kubernetes, and other environments.

This article explains how to install and configure Zookeeper, covering local, docker, kubernetes, and other environments. The following is just a quick example installation guide; for setting up a production-ready cluster, please refer to the Zookeeper official documentation.

Local Download

Download Zookeeper

Please go to the Apache Zookeeper download page to download the latest version of the Zookeeper release package.

Unpack the downloaded Zookeeper package:

  1. tar -zxvf apache-zookeeper-3.8.3.tar.gz
  2. cd apache-zookeeper-3.8.3

Start Zookeeper

Before starting Zookeeper, you need to create the file conf/zoo.cfg in the root directory:

  1. tickTime=2000
  2. clientPort=2181
  3. admin.enableServer=false

Here are detailed explanations of some parameters:

  • tickTime: The basic time setting used by Zookeeper, tickTime is the heartbeat detection interval, 2*tickTime is the maximum session timeout (in milliseconds).
  • clientPort: The listening port, clients can connect to the Zookeeper server through this port.
  • admin.enableServer: The maintenance port, default is 8080, recommended to turn off to prevent conflicts with Spring web applications.

Next, you can start Zookeeper in standalone mode:

  1. bin/zkServer.sh start

Test Connection to ZooKeeper

Run the following command to connect to the just started Zookeeper server:

  1. $ bin/zkCli.sh -server 127.0.0.1:2181

Once connected successfully, you will see the following output:

  1. Connecting to localhost:2181
  2. ...
  3. Welcome to ZooKeeper!
  4. JLine support is enabled
  5. [zkshell: 0]

Execute the following command to view the root node contents:

  1. [zkshell: 8] ls /
  2. [zookeeper]

Docker

To start Zookeeper using Docker, please ensure you have correctly installed Docker on your local machine.

Run the following command to start the Zookeeper server:

  1. docker run --name some-zookeeper -p 2181:2181 -e JVMFLAGS="-Dzookeeper.admin.enableServer=false" --restart always -d zookeeper:3.8.3

If you want to specify the /conf configuration file, you can mount the local file to the Docker container:

  1. $ docker run --name some-zookeeper --restart always -e JVMFLAGS="-Dzookeeper.admin.enableServer=false" -d -v $(pwd)/zoo.cfg:/conf/zoo.cfg

Kubernetes

You can quickly install Zookeeper to a Kubernetes cluster using the example configuration provided by the Dubbo community.

  1. kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-kubernetes/master/deploy/kubernetes/zookeeper.yaml

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)