Zookeeper Installation, Configuration and Tooling

Installation

  1. Go to https://zookeeper.apache.org/releases.html#download
  2. Get it from a mirror (zookeeper.apache.org)
    $ tar -zxvf zookeeper-3.4.6.tar.gz
    $ rm -rf zookeeper-3.4.6.tar.gz
    
  3. 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 the conf directory which contains zookeeper configuration.
  4. 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.
  5. Change the location of the logs in the conf directory.
    1. Open zoo.cfg and change the line from dataDir=/tmp/zookeeper to dataDir=/home/explorer436/Downloads/apache-zookeeper-3.8.4-bin/logs
  6. clientPort=2181
    1. This is the port that zookeeper will listen for client applications.
    2. 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:

  1. DataDir: The location where ZooKeeper will store the in-memory database snapshots
  2. DataLogDir: Location where the logged snapshot of Znode structure will be generated.
  3. TickTime: The length of a single tick, which is the basic time unit used by ZooKeeper, as measured in milliseconds.
  4. ClientPort=ZooKeeper client socket connection port
  5. InitLimit= Timeout ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader
  6. SyncLimit=Limits how far out of date a server can be from a leader ,within a configured time period all nodes are in sync.
  7. Server Host: Port details : Can be configured as “server.ID=server host : quorum port: leader election port”
  8. ElectionAlg: Zookeeper uses “FastLeaderElection” default algorithm.
  9. 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

  1. a command line tool provided with ZooKeeper - perform read/set, data/get, data/create/delete operations through command utility
  2. 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

  1. ZooInspector
    1. It is a Java Swing based application for browsing and editing ZooKeeper instances.
    2. Provides command line utility to start ZooInspector as -run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux).
    3. Load connection settings from a zookeeper properties file or can enter connection information for zookeeper instance.
    4. Gives Browseable tree view of the nodes as shown above.
    5. Supports to view the lock data associated with the node.
    6. Supports to view the ACL’s currently applied to a node
    7. Supports to view the metadata for a node (Version, Number of Children, Last modified Time, etc.)
    8. 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.
  2. Exhibitor web console
    1. available as node browser

References

  1. https://www.linkedin.com/pulse/how-implement-zookeeper-locking-mechanism-minal-bagade/

Links to this note