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.
Please go to the Apache Zookeeper download page to download the latest version of the Zookeeper release package.
Unpack the downloaded Zookeeper package:
tar -zxvf apache-zookeeper-3.8.3.tar.gz
cd apache-zookeeper-3.8.3
Before starting Zookeeper, you need to create the file conf/zoo.cfg
in the root directory:
tickTime=2000
clientPort=2181
admin.enableServer=false
Here are detailed explanations of some parameters:
Next, you can start Zookeeper in standalone mode:
bin/zkServer.sh start
Run the following command to connect to the just started Zookeeper server:
$ bin/zkCli.sh -server 127.0.0.1:2181
Once connected successfully, you will see the following output:
Connecting to localhost:2181
...
Welcome to ZooKeeper!
JLine support is enabled
[zkshell: 0]
Execute the following command to view the root node contents:
[zkshell: 8] ls /
[zookeeper]
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:
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:
$ docker run --name some-zookeeper --restart always -e JVMFLAGS="-Dzookeeper.admin.enableServer=false" -d -v $(pwd)/zoo.cfg:/conf/zoo.cfg
You can quickly install Zookeeper to a Kubernetes cluster using the example configuration provided by the Dubbo community.
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-kubernetes/master/deploy/kubernetes/zookeeper.yaml