展示您最近执行的11个命令的历史记录。例如:
[zk: localhost:2181(CONNECTED) 43] history 33 - ls / 34 - create /acl_auth_test myData 35 - addauth digest user1:12345 36 - setAcl /acl_auth_test auth:user1:12345:crwad 37 - getAcl /acl_auth_test 38 - ls / 39 - delete /acl_auth_test 40 - cls 41 - create /acl_auth_test myData 42 - addauth digest user1:12345 43 - history
显示 ZooKeeper 客户端/CLI 的版本。例如:
[zk: localhost:2181(CONNECTED) 44] version ZooKeeper CLI version: 3.9.1-1398af177833412e9ead6b9bb737dc9fd7418a45, built on 2023-10-04 09:54 UTC
退出 CLI 窗口。例如:
[zkshell: 1] quit
关闭此客户端/会话。例如:
[zkshell: 0] close 2019-03-09 06:42:22,178 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@528] - EventThread shut down for session: 0x10007ab7c550006 2019-03-09 06:42:22,179 [myid:] - INFO [main:ZooKeeper@1346] - Session: 0x10007ab7c550006 closed
打开/关闭是否打印监听信息(watche)的开关。例如:
[zkshell: 0] printwatches printwatches is on [zkshell: 1] printwatches off [zkshell: 2] printwatches printwatches is off [zkshell: 3] printwatches on [zkshell: 4] printwatches printwatches is on
在 leader 和 followers 之间同步一个节点的数据(异步同步),例如:
[zkshell: 14] sync / [zkshell: 15] Sync is OK
使用历史索引,重新执行某条历史命。语法如下:
redo cmdno
其中,cmdno 为历史命令的索引,从 0 开始。
例如:
[zkshell: 4] history 0 - ls / 1 - get /consumers 2 - get /hbase 3 - ls /hbase 4 - history [zkshell: 5] redo 3 [backup-masters, draining, flush-table-proc, hbaseid, master-maintenance, meta-region-server, namespace, online-snapshot, replication, rs, running, splitWAL, switch, table, table-lock]
连接 ZooKeeper 服务器。语法如下:
connect host:port
其中,host 为主机地址,port 为端口。
例如:
[zkshell: 4] connect 2019-03-09 06:43:33,179 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /127.0.0.1:35144, server: localhost/127.0.0.1:2181 2019-03-09 06:43:33,189 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1421] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x10007ab7c550007, negotiated timeout = 30000 connect "localhost:2181,localhost:2182,localhost:2183" # 连接远程服务器 [zkshell: 5] connect remoteIP:2181
获取特定路径下的所有子节点数,例如:
[zkshell: 1] getAllChildrenNumber / 73779 [zkshell: 2] getAllChildrenNumber /ZooKeeper 2 [zkshell: 3] getAllChildrenNumber /ZooKeeper/quota 0
获取此会话创建的所有临时节点,例如:
# 创建临时节点 [zkshell: 1] create -e /test-get-ephemerals "ephemeral node" Created /test-get-ephemerals # 查看回话创建的临时节点 [zkshell: 2] getEphemerals [/test-get-ephemerals] [zkshell: 3] getEphemerals / [/test-get-ephemerals] # 创建新的临时节点 [zkshell: 4] create -e /test-get-ephemerals-1 "ephemeral node" Created /test-get-ephemerals-1 # 查看创建的临时节点 [zkshell: 5] getEphemerals /test-get-ephemerals test-get-ephemerals test-get-ephemerals-1 [zkshell: 6] getEphemerals /test-get-ephemerals [/test-get-ephemerals-1, /test-get-ephemerals] [zkshell: 7] getEphemerals /test-get-ephemerals-1 [/test-get-ephemerals-1]