Zookeeper Installation, Configuration and Tooling
Table of Contents
Installation
- Go to https://zookeeper.apache.org/releases.html#download
- Get it from a mirror (zookeeper.apache.org)
$ tar -zxvf zookeeper-3.4.6.tar.gz $ rm -rf zookeeper-3.4.6.tar.gz
- Inside the zookeeper folder, we will find everything we need such as the binaries, all its dependencies, the source code with the documentation and so on. The important parts for us are the
bin
directory which contains the scripts to run and control zookeeper and theconf
directory which contains zookeeper configuration. - Create a location for logs
$ cd zookeeper-3.4.6 $ mkdir logs $ cd ../conf $ cp zoo_sample.cfg zoo.cfg
zoo.cfg
is the name of the file that zookeeper will look for during runtime. This file will configure zookeeper to run as a standalone server. In other words, it will run as a simple process instead of running as a cluster. This is ideal for development environment in local machines. - Change the location of the logs in the
conf
directory.- Open
zoo.cfg
and change the line fromdataDir=/tmp/zookeeper
todataDir=/home/explorer436/Downloads/apache-zookeeper-3.8.4-bin/logs
- Open
clientPort=2181
- This is the port that zookeeper will listen for client applications.
- In our applications, we have to use this port number.
Configuration
The below section provides brief detail about possible configuration that can be considered for client and server environment. ZooKeeper maintains configuration in properties file and they are loaded on startup. ZooKeeper properties file will contain below connection configurations:
- DataDir: The location where ZooKeeper will store the in-memory database snapshots
- DataLogDir: Location where the logged snapshot of Znode structure will be generated.
- TickTime: The length of a single tick, which is the basic time unit used by ZooKeeper, as measured in milliseconds.
- ClientPort=ZooKeeper client socket connection port
- InitLimit= Timeout ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader
- SyncLimit=Limits how far out of date a server can be from a leader ,within a configured time period all nodes are in sync.
- Server Host: Port details : Can be configured as “server.ID=server host : quorum port: leader election port”
- ElectionAlg: Zookeeper uses “FastLeaderElection” default algorithm.
- CnxTimeout: Sets the timeout value for opening connections for leader election notifications
Note: Default configurations would be used as recommended by Zookeeper.
Starting zookeeper
[explorer436@explorer436-p50-20eqs27p03 bin]$ cd bin
[explorer436@explorer436-p50-20eqs27p03 bin]$ ./zkServer.sh
ZooKeeper JMX enabled by default
Using config: /home/explorer436/Downloads/apache-zookeeper-3.8.4-bin/bin/../conf/zoo.cfg
Usage: ./zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|version|restart|status|print-cmd}
[explorer436@explorer436-p50-20eqs27p03 bin]$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/explorer436/Downloads/apache-zookeeper-3.8.4-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[explorer436@explorer436-p50-20eqs27p03 bin]$
Zookeeper command line client
bin/zkCli.cmd
or bin/zkCli.sh
- a command line tool provided with ZooKeeper - perform read/set, data/get, data/create/delete operations through command utility
- A great tool for visualization and debugging zookeeper
[explorer436@explorer436-p50-20eqs27p03 bin]$ ./zkCli.sh
It is a normal shell.
Type help
to see all the commands that the client provides us.
[zk: localhost:2181(CONNECTED) 11] help
ZooKeeper -server host:port -client-configuration properties-file cmd args
addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
addauth scheme auth
close
config [-c] [-w] [-s]
connect host:port
create [-s] [-e] [-c] [-t ttl] path [data] [acl]
delete [-v version] path
deleteall path [-b batch size]
delquota [-n|-b|-N|-B] path
get [-s] [-w] path
getAcl [-s] path
getAllChildrenNumber path
getEphemerals path
history
listquota path
ls [-s] [-w] [-R] path
printwatches on|off
quit
reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
redo cmdno
removewatches path [-c|-d|-a] [-l]
set [-s] [-v version] path data
setAcl [-s] [-v version] [-R] path acl
setquota -n|-b|-N|-B val path
stat [-w] path
sync path
version
whoami
Run ls
on the root Znode.
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 3] create /parent "some parent data"
Created /parent
[zk: localhost:2181(CONNECTED) 4] ls /
[parent, zookeeper]
[zk: localhost:2181(CONNECTED) 5] create /parent/child "some child data"
Created /parent/child
[zk: localhost:2181(CONNECTED) 6] ls /
[parent, zookeeper]
[zk: localhost:2181(CONNECTED) 7] ls /parent
[child]
Although zookeeper client makes those Znodes look like real files on our computer, there are no Znode files stored anywhere in our file system. It is just a representation of the data model stored within zookeeper in-memory.
Other Tools
Browser for ZooKeeper Nodes
- ZooInspector
- It is a Java Swing based application for browsing and editing ZooKeeper instances.
- Provides command line utility to start ZooInspector as
-run zooInspector.cmd
(on Windows) orzooInspector.sh
(on Linux). - Load connection settings from a zookeeper properties file or can enter connection information for zookeeper instance.
- Gives Browseable tree view of the nodes as shown above.
- Supports to view the lock data associated with the node.
- Supports to view the ACL’s currently applied to a node
- Supports to view the metadata for a node (Version, Number of Children, Last modified Time, etc.)
- Supports to delete locked node entry. The access rights can be set to restrict operations for specific users, while currently no such access restrictions applied.
- Exhibitor web console
- available as node browser