• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
ZooKeeper | Command Line Utilities: "zkCli"
  1. Command Line Utilities
  2. zkCli commands
  3. View commands history
  4. Create zNodes
  5. Set data to a zNode
  6. Get data of a zNode
  7. ZooKeeper ensemble configuration
  8. Close connection to ZooKeeper
  9. Connect to ZooKeeper
  10. Quit zkCli
  11. Remove an instance from ZooKeeper ensemble
  12. Add new instance to ZooKeeper ensemble

  1. Command Line Utilities
    The ZooKeeper client provides a list of commands that allow you to access and manipulate zNodes in ZooKeeper.

    You can run the command line and specify one or multiple ZooKeeper instances:
    $ ${ZK_HOME}/bin/zkCli.sh

    $ ${ZK_HOME}/bin/zkCli.sh -server localhost:2181

    $ ${ZK_HOME}/bin/zkCli.sh -server "localhost:2181,localhost:2182,localhost:2183"

    You can execute directly a command as follows:
    $ ${ZK_HOME}/bin/zkCli.sh -server localhost:2181 COMMAND ARGUMENTS
  2. zkCli commands
    • history
    • version
    • whoami

    • connect host:port
    • close

    • quit

    • config [-c] [-w] [-s]
    • reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]

    • ls [-s] [-w] [-R] path
    • stat [-w] path

    • get [-s] [-w] [-b] [-x] path
    • getAllChildrenNumber path
    • getEphemerals path

    • set path data [-s] [-v version] [-b]

    • getAcl [-s] path
    • setAcl [-s] [-v version] [-R] path acl

    • create [-s] [-e] [-c] [-t ttl] path [data] [acl]

    • delete [-v version] path
    • deleteall path [-b batch size]

    • addauth scheme auth

    • listquota path
    • setquota -n|-b|-N|-B val path
    • delquota [-n|-b|-N|-B] path

    • addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
    • printwatches on|off
    • removewatches path [-c|-d|-a] [-l]

    • redo cmdno

    • sync path
  3. View commands history
    $ [zk: localhost:2181(CONNECTED) 0] history
    0 - ls /
    1 - history
  4. Create zNodes
    Create zNode:
    $ [zk: localhost:2181(CONNECTED) 0] create /znode1
    Created /znode1

    Create zNode with data:
    $ [zk: localhost:2181(CONNECTED) 0] create /znode2 znode2_data
    Created /znode2
  5. Set data to a zNode
    $ [zk: localhost:2181(CONNECTED) 0] set /znode1 znode1_data
  6. Get data of a zNode
    $ [zk: localhost:2181(CONNECTED) 0] get /znode1
    znode1_data
  7. ZooKeeper ensemble configuration
    $ [zk: localhost:2181(CONNECTED) 0] config
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    server.3=localhost:2890:3890:participant;0.0.0.0:2183
    version=0
  8. Close connection to ZooKeeper
    $ [zk: localhost:2181(CONNECTED) 0] close
    2016-07-10 19:24:49,241 [myid:] - INFO  [main:ZooKeeper@1110] - Session: 0x100002d7e410003 closed
  9. Connect to ZooKeeper
    $ [zk: localhost:2181(CLOSED) 0] connect
    2016-07-10 19:25:00,934 [myid:] - INFO  [main:ZooKeeper@716] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000

    $ [zk: localhost:2181(CLOSED) 0] connect localhost:2181
    2016-07-10 19:25:00,934 [myid:] - INFO  [main:ZooKeeper@716] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000

    $ [zk: localhost:2181(CLOSED) 0] connect "localhost:2181,localhost:2182,localhost:2183"
    2016-07-10 19:25:00,934 [myid:] - INFO  [main:ZooKeeper@716] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000
  10. Quit zkCli
    $ [zk: localhost:2181(CONNECTED) 0] quit
    2016-07-10 19:28:40,215 [myid:] - INFO  [main:ZooKeeper@1110] - Session: 0x100002d7e410004 closed
  11. Remove an instance from ZooKeeper ensemble
    Check the following constraints of the reconfig command:
    ► You get an error if "reconfigEnabled" is disabled (default): "reconfigEnabled" ► You need to enable the option "reconfigEnabled=true" in the configuration file ("zoo.cfg").
    ► You have to authenticate with an authorized user to execute the "reconfig" command (see this page zk-super-user.php for instructions on how to create an authorized user).

    $ [zk: localhost:2181(CONNECTED) 2] reconfig -remove 3
    Committed new configuration:
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    version=600000004
  12. Add new instance to ZooKeeper ensemble
    $ [zk: localhost:2181(CONNECTED) 0] reconfig -add server.3=localhost:2890:3890:participant;0.0.0.0:2183
    Committed new configuration:
    server.1=localhost:2888:3888:participant;0.0.0.0:2181
    server.2=localhost:2889:3889:participant;0.0.0.0:2182
    server.3=localhost:2890:3890:participant;0.0.0.0:2183
    version=600000003
© 2025  mtitek