mtitek.com  MTI TEK
 Home |Big Data |Samples |Install |Tutorials |References |Books |Contact

ZooKeeper ▸ Command Line Utilities: "zkCli"
  1. Command Line Utilities
  2. zkCli commands
  3. View commands history
  4. Close connection to ZooKeeper
  5. Connect to ZooKeeper
  6. Quit zkCli
  7. Create zNodes
  8. Set data to a zNode
  9. Get data of a zNode
  10. ZooKeeper ensemble configuration
  11. Add new instance to ZooKeeper ensemble
  12. Remove an instance from 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_ROOT}/bin/zkCli.sh
    
    ${ZK_ROOT}/bin/zkCli.sh -server localhost:2181
    
    ${ZK_ROOT}/bin/zkCli.sh -server "localhost:2181,localhost:2182,localhost:2183"
    
    You can execute directly a command as follows:
    ${ZK_ROOT}/bin/zkCli.sh -server localhost:2181 COMMAND ARGUMENTS
    
  2. zkCli commands
    history
    
    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] path
    getAcl [-s] path
    
    set [-s] [-v version] path data
    setAcl [-s] [-v version] path acl
    
    create [-s] [-e] [-c] [-t ttl] path [data] [acl]
    
    delete [-v version] path
    deleteall path
    
    addauth scheme auth
    
    listquota path
    setquota -n|-b val path
    delquota [-n|-b] path
    
    printwatches on|off
    removewatches path [-c|-d|-a] [-l]
    
    redo cmdno
    
    sync path
    
    Notes:
    ▸ The command 'ls2' has been deprecated. Please use 'ls [-s] path' instead.
    ls2 path [watch]
    
    ▸ The command 'rmr' has been deprecated. Please use 'deleteall' instead.
    rmr path
    
  3. View commands history
    [zk: localhost:2181(CONNECTED) 2] history
    0 - ls /
    1 - get /abc
    2 - history
    
  4. Close connection to ZooKeeper
    [zk: localhost:2181(CONNECTED) 4] close
    2016-07-10 19:24:49,241 [myid:] - INFO  [main:ZooKeeper@1110] - Session: 0x100002d7e410003 closed
    
  5. Connect to ZooKeeper
    [zk: localhost:2181(CLOSED) 5] 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) 5] 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) 5] 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
    
  6. Quit zkCli
    [zk: localhost:2181(CONNECTED) 6] quit
    2016-07-10 19:28:40,215 [myid:] - INFO  [main:ZooKeeper@1110] - Session: 0x100002d7e410004 closed
    
  7. Create zNodes
    Create zNode:
    [zk: localhost:2181,localhost:2182,localhost:2183(CONNECTED) 0] create /znode1
    Created /znode1
    
    Create zNode with data:
    [zk: localhost:2181,localhost:2182,localhost:2183(CONNECTED) 1] create /znode2 znode2_data
    Created /znode2
    
  8. Set data to a zNode
    [zk: localhost:2181,localhost:2182,localhost:2183(CONNECTED) 1] set /znode1 znode1_data
    
  9. Get data of a zNode
    [zk: localhost:2181,localhost:2182,localhost:2183(CONNECTED) 0] get /znode1
    znode1_data
    
  10. 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
    version=500000005
    
  11. Add new instance to ZooKeeper ensemble
    Notes:
    ▸ You have to enable the option "reconfigEnabled" to 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) 1] 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
    
  12. Remove an instance from ZooKeeper ensemble
    Notes:
    ▸ You have to enable the option "reconfigEnabled" to 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
    


© mtitek.com