zookeeper

https://zookeeper.apache.org/

Prerequisites

Install JDK on each node, see “Install Java Development Environment”.

Get shell script install_java_bin.

Download the java binary packages:

curl -LO https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.9.3/apache-zookeeper-3.9.3-bin.tar.gz

Check sum:

$ sha512sum apache-zookeeper-3.9.3-bin.tar.gz 
d44d870c1691662efbf1a8baf1859c901b820dc5ff163b36e81beb27b6fbf3cd31b5f1f075697edaaf6d3e7a4cb0cc92f924dcff64b294ef13d535589bdaf143  apache-zookeeper-3.9.3-bin.tar.gz

Deploy

Install the java packages on each node:

$ install_java_bin zookeeper apache-zookeeper-3.9.3-bin.tar.gz /opt
$ sudo chown ubuntu:ubuntu /opt/zookeeper

Configure

Copy file /opt/zookeeper/conf/zoo_sample.cfg to /opt/zookeeper/conf/zoo.cfg and edit it:

 # The number of milliseconds of each tick
 tickTime=2000
-# The number of ticks that the initial 
+# The number of ticks that the initial
 # synchronization phase can take
 initLimit=10
-# The number of ticks that can pass between 
+# The number of ticks that can pass between
 # sending a request and getting an acknowledgement
 syncLimit=5
 # the directory where the snapshot is stored.
-# do not use /tmp for storage, /tmp here is just 
+# do not use /tmp for storage, /tmp here is just
 # example sakes.
-dataDir=/tmp/zookeeper
+dataDir=/opt/tmp/zookeeper
 # the port at which the clients will connect
 clientPort=2181
 # the maximum number of client connections.
 # increase this if you need to handle more clients
 #maxClientCnxns=60
 #
-# Be sure to read the maintenance section of the 
+# Be sure to read the maintenance section of the
 # administrator guide before turning on autopurge.
 #
 # https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
 #metricsProvider.httpPort=7000
 #metricsProvider.exportJvmInfo=true
 
+server.0=las0:2888:3888
+server.1=las1:2888:3888
+server.2=las2:2888:3888

This file need to be copied to all nodes to the same path.

Create the directory for ${dataDir} on each node:

$ sudo mkdir -p /opt/tmp/zookeeper
$ sudo chown ubuntu:ubuntu /opt/tmp/zookeeper

Create file myid whose content is an unique ID number in directory /opt/tmp/zookeeper for each node. For example, on host las1:

$ echo 1 >/opt/tmp/zookeeper/myid

Run

Check version:

$ zkServer.sh version
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Apache ZooKeeper, version 3.9.3 2024-10-17 23:21 UTC

Start the service on each node:

$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Show java processes:

$ jps -lm
3155810 org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/zookeeper/bin/../conf/zoo.cfg
3157879 sun.tools.jps.Jps -lm

Check service status:

$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

Note

The last line will be Mode: leader if run the command on a leader node. Only one of the nodes should be ‘leader’ and the others should be ‘follower’.

Stop the service on one node:

$ zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

There must be at least 3 nodes to make zookeeper functions properly.

Usage

Start the client:

$ zkCli.sh -server las0

Check server status:

$ echo srvr | nc las2 2181
Zookeeper version: 3.9.3-c26634f34490bb0ea7a09cc51e05ede3b4e320ee, built on 2024-10-17 23:21 UTC
Latency min/avg/max: 0/0.0/0
Received: 2
Sent: 1
Connections: 1
Outstanding: 0
Zxid: 0x200000002
Mode: leader
Node count: 5
Proposal sizes last/min/max: 48/48/48

The admin service is started on port 8080 on each node by default. Open http://las0:8080/commands to see the list of available commands.