A command line program designed to replace zkCli.sh, which comes with the ZooKeeper distribution. This program is much cleaner and easier to use.
The original project, which contained both the API and CLI, was broken into two separate projects. The last commit before the original repository was cloned is 6ad2c34.
As of version 1.7, the CLI program can be downloaded from GitHub. For versions prior to 1.7, download from the Maven Central Repository
Unpacking the assembly will produce the following output:
zookeeper-cli-<version>/
+ bin/
+ zk
+ zk.bat
+ ...
+ lib/
+ ...For convenience, you might place zookeeper-cli-<version>/bin/zk in your PATH or create an alias.
The zk program uses JLine for console input similar to what you might expect in modern shells. For example, ^p and ^n can be used to scroll back and forth through the command history.
It also supports TAB auto-completion as follows:
- Pressing TAB on the first argument attempts to auto-complete as though the user were entering a command. Therefore, pressing TAB on an empty line produces a list of all available commands.
- Pressing TAB on the second, and all subsequent, arguments attempts to auto-complete as though the user were entering a ZooKeeper node path. This feature was designed to very closely mimic file system auto-completion in the shell. It is sensitive to the current path context, so you only see relevant subpaths.
Unlike zkCli.sh, the zk program supports relative node paths and the ability to essentially cd to a path, thus setting a current working path. In all commands requiring paths, both absolute and relative forms may be given. An absolute path starts with /, so the current working path is ignored. Otherwise, the relative path is resolved in the context of the current working path.
Both . and .. can be used in path expressions.
Show zk usage information.
zk
zk -?
zk --helpShow list of commands.
zk --help help
zk -? helpDisplay usage information for the ls command.
zk --help ls
zk -? lsPrint version information.
zk --versionConnect to a ZooKeeper cluster by specifying at least one of its servers.
zk server1.com:2181The port number may be omitted if ZooKeeper servers are listening on port 2181.
zk server1.com server2.comSpecify a root path, akin to chroot.
zk -p /foo server1.comAllow connection to a ZooKeeper server even if a quorum has not been established.
zk -r server1.comExecute a command without entering the zk shell.
zk -c "get foo/bar" server1.comExecute commands from an external file whose character encoding is presumed to be UTF-8.
zk -f my.commands server1.comSpecify the character encoding that applies to an external command file.
zk -f my.commands -e iso-8859-1 server1.comExecute multiple commands without entering the zk shell.
zk -f /dev/tty server1.com
ls -l /hbase
ls -r /hadoop
^DIn some cases, it becomes necessary to provide arguments, such as commands or values, as quoted strings from either the OS shell or the zk shell. The following examples illustrate the correct format, particularly for escaping embedded quotes.
From command shells, such as zsh or bash.
zk -c "set -f /foo \"bar: 7\"" server1.comor
zk -c 'set -f /foo "bar: 7"' server1.comThe -c argument is parsed by the command shell and presented to zk as a single argument in the following form.
set -f /foo "bar: 7"The zk shell will then split this string into distinct tokens similar to the manner done by zsh or bash, leading to the following tokens.
set
-f
/foo
bar: 7The following depicts a more complex scenario in which quoted strings tokenized by zk contain embedded quotes. Consider a slightly more complicated form of the previous example.
zk -c "set -f /foo \"bar: \\\"7\\\"\"" server1.comor
zk -c 'set -f /foo "bar: \"7\""' server1.comThe -c argument sent to zk by the command shell appears as follows.
set -f /foo "bar: \"7\""Which is then tokenized by zk.
set
-f
/foo
bar: "7"Send ZooKeeper log messages to a file other than the default of $HOME/zk.log.
zk --log /tmp/zk.log server1.comCaptures all ZooKeeper log messages rather than the default severity level of warn.
zk --level all server1.comDisable ZooKeeper log messages.
zk --nolog server1.comGet list of all commands.
zk> helpGet help for a specific command.
zk> help lsChange the current working path.
zk> cd foo/barChange the current working path to the parent.
zk> cd ..Return to previous working path.
zk> cd -Change the current working path to /.
zk> cdDisplay the current working path.
zk> pwdShow child nodes of the current working path.
zk> lsShow child nodes for paths foo and ../bar
zk> ls foo ../barRecursively show child nodes of entire ZooKeeper node space.
zk> ls -r /Show child nodes in long format, which appends node names with / if it contains children or * if ephemeral, and in all cases, the node version.
zk> ls -lDisplay hex/ASCII output of data associated with node at current working path.
zk> getDisplay data of node /foo/bar as string encoded as ISO-8859-1.
zk> get -s -e iso-8859-1 /foo/barShow internal ZooKeeper state of nodes this and that.
zk> stat this thatShow state of node /foo in compact format.
zk> stat -c /fooShow ACL for node /zookeeper.
zk> getacl /zookeeperCreate node foo with no attached data.
zk> mk fooCreate node /foo/bar/baz and all intermediate nodes, if necessary.
zk> mk -r /foo/bar/bazCreate ephemeral node lock_ with monotonically-increasing sequence appended to name.
zk> mk -E -S lock_Create node bar with data hello world encoded as UTF-16.
zk> mk -e utf-16 "hello world"Create node foo with time-to-live of 10 seconds.
zk> mk -T 10000 fooSet data of node /foo/bar as goodbye world whose current version in ZooKeeper is 19.
zk> set -v 19 /foo/bar "goodbye world"Set data of node lock/master with data from file /tmp/master.bin and version 31.
zk> set -v 31 lock/master @/tmp/master.binForcefully clear the data of node this/that without specifying the version.
zk> set -f this/thatReplace ACL of node foo/bar with world:anyone=* (all permissions) and version 17.
zk> setacl -v 17 foo/bar world:anyone=*Add ACL world:anyone=rw (read/write) to node foo/bar, ignoring version.
zk> setacl -a -f foo/bar world:anyone=rwRemove ACL world:anyone=rwcd (read/write/create/delete) from node foo/bar with version 23.
zk> setacl -r -v 23 foo/bar world:anyone=rwcdDelete node /lock/master whose current version in ZooKeeper is 7.
zk> rm -v 7 /lock/masterRecursively delete node instances and its children, forcefully doing so without specifying the version.
zk> rm -r -f instancesThe find command can be very useful, but also quite destructive when applying mutating operations. A general rule of thumb is to verify nodes that are expected to match the regular expression before applying commands that modify state. All patterns are strictly regular expressions as defined by Java 6 (http://bit.ly/zk-regex).
Find and print all nodes matching the regular expression locks relative to node foo. Note in the first example that the print operation is assumed if omitted.
zk> find locks foo
zk> find locks foo --exec printRecursively find and print all nodes matching the regular expression lock_.* relative to node foo.
zk> find -r lock_.* fooRecursively find all nodes matching locks relative to node foo and create a child node with the prefix lock_ whose suffix is a monotonically-increasing sequence and whose associated data is this is a lock.
zk> find -r locks foo --exec mk -S lock_ "this is a lock"Display data in string format for all nodes relative to foo/locks matching the regular expression lock_\d+.
zk> find lock_\d+ foo/locks --exec get -sSet data for all nodes relative to foo/locks matching the regular expression lock_\d+ to the value this was a lock.
zk> find lock_\d+ foo/locks --exec set "this was a lock"Find all nodes relative to foo/locks matching the regular expression lock_\d+ and recursively delete those nodes and their children.
zk> find lock_\d+ foo/locks --exec rm -rTell find to suppress display of matching nodes.
zk> find --quiet ...
zk> find -q ...Tell find to stop executing the given command on error (default is to continue to the next node).
zk> find --halt ...
zk> find -h ...Show configuration of zk connection to a ZooKeeper cluster, including the session state and location of the log file.
zk> configQuit the program.
zk> quitReleases are published on GitHub. The release.sh script automates the entire process, which depends on the GitHub CLI being installed.
The version of the release is derived from the version specified in build.sbt. A new release on GitHub generates a corresponding tag, so the assumption is that the version number has been appropriately incremented. Otherwise, the release creation process will fail.
If the release process is successful, a new tag of the format v<version> is automatically created. For example, if the package version in build.sbt is 1.2.3, then the corresponding tag is v1.2.3.
If the release process was problematic in any way, it can be deleted using the following command.
gh release delete --cleanup-tag --yes <tag>Once released, push all changes to GitHub. The new tag will be created on the remote repository.
$ git push origin master
$ git pull --tags originPlease refer to the contribution guidelines when reporting bugs and suggesting improvements.
Copyright 2015 David Edwards
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.