Apache ZooKeeper Command Line Interface (CLI) usage
Apache ZooKeeper is a software project of the Apache Software Foundation. It is essentially a distributed hierarchical key-value store, which is used to provide a distributed configuration service, synchronization service, and naming registry for large distributed systems. ZooKeeper was a sub-project of Hadoop but is now a top-level project in its own right.
ZooKeeper's architecture supports high availability through redundant services. The clients can thus ask another ZooKeeper leader if the first fails to answer. ZooKeeper nodes store their data in a hierarchical name space, much like a file system or a tree data structure. Clients can read from and write to the nodes and in this way have a shared configuration service. Updates are totally ordered.
1) A machine with Ubuntu 14.04 LTS operating system.
2) Apache ZooKeeper 3.4.6 pre installed (How to set up single server ZooKeeper on Ubuntu 14.04)
ZooKeeper Command Line Interface (CLI) usage
ZooKeeper Command Line Interface (CLI) is used to interact with the ZooKeeper ensemble for development purpose. It is useful for debugging and working around with different options.
To perform ZooKeeper CLI operations, first turn on your ZooKeeper server ("bin/zkServer.sh start") and then, ZooKeeper client ("bin/zkCli.sh"). Once the client starts, you can perform the following operation:
1) Create znodes
2) Get data
3) Watch znode for changes
4) Set data
5) Create children of a znode
6) List children of a znode
7) Check Status
8) Remove / Delete a znode
Step 1 - Change the directory to /usr/local/zookeeper/bin
Step 2 - Start zookeeper server
Step 3 - Start client
Create a znode with the given path. The flag argument specifies whether the created znode will be ephemeral, persistent, or sequential. By default, all znodes are persistent.
a) Ephemeral znodes - (flag: e) will be automatically deleted when a session expires or when the client disconnects.
b) Sequential znodes - guaranty that the znode path will be unique.
c) Persistent - ZooKeeper ensemble will add sequence number along with 10 digit padding to the znode path. For example, the znode path /myapp will be converted to /myapp0000000001 and the next sequence number will be /myapp0000000002. If no flags are specified, then the znode is considered as persistent.
To create a Persistant(default) znode, shown below.
To create a Sequential znode, add -s flag as shown below.
To create an Ephemeral znode, add -e flag as shown below.
It returns the associated data of the znode and metadata of the specified znode. You will get information such as when the data was last modified, where it was modified, and information about the data. This CLI is also used to assign watches to show notification about the data.
To access a sequential znode, you must enter the full path of the znode.
Watch znode for changes
Watches show a notification when the specified znode or znode's children data changes. You can set a watch only in get command.
Set the data of the specified znode. Once you finish this set operation, you can check the data using the get CLI command.
Create children of a znode
Creating children is similar to creating new znodes. The only difference is that the path of the child znode will have the parent path as well.
This command is used to list and display the children of a znode.
Status describes the metadata of a specified znode. It contains details such as Timestamp, Version number, ACL, Data length, and Children znode.
Remove a Znode
Removes a specified znode and recursively all its children. This would happen only if such a znode is available.
Dont forget to stop zookeeper server
Please share this blog post and follow me for latest updates on