ZooKeeper 3.5.5 基础使用

这里记录的是使用zk自带的客户端工具 zkCli.sh 进行简单的操作,以后有时间再补充。3.5.5 版本和之前的3.4版本相比,命令的使用还是有不少差别的。

最好的学习方式就是查看在线帮助文档:

https://zookeeper.apache.org/doc/r3.5.5/zookeeperStarted.html

切换到 zk 的 bin目录,使用命令 zkCli.sh 连接到本机的 zk 服务,启动成功后,会出现如下信息:

Welcome to ZooKeeper!
2021-07-31 23:34:24,869 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-07-31 23:34:25,105 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /127.0.0.1:57418, server: localhost/127.0.0.1:2181
2021-07-31 23:34:25,149 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1000003ea520001, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
使用help命令,显示 zk支持的操作如下:

ZooKeeper -server host:port cmd args
    addauth scheme auth
    close 
    config [-c] [-w] [-s]
    connect host:port
    create [-s] [-e] [-c] [-t ttl] path [data] [acl]
    delete [-v version] path
    deleteall path
    delquota [-n|-b] path
    get [-s] [-w] path
    getAcl [-s] path
    history 
    listquota path
    ls [-s] [-w] [-R] path
    ls2 path [watch]
    printwatches on|off
    quit 
    reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
    redo cmdno
    removewatches path [-c|-d|-a] [-l]
    rmr path
    set [-s] [-v version] path data
    setAcl [-s] [-v version] [-R] path acl
    setquota -n|-b val path
    stat [-w] path
    sync path

简单的记录一下:

1、ls / 显示/根节点下的节点

我这里显示

[zk: localhost:2181(CONNECTED) 1] ls /
[persistent_sequential_node0000000001, persistent_sequential_node0000000002, test, zookeeper]

2、create 创建节点,支持创建空节点

[zk: localhost:2181(CONNECTED) 1] create /test/test
Created /test/test


3、查看节点

[zk: localhost:2181(CONNECTED) 2] ls /test
[name, snode, test]
 

4、set path value 更新path的值为value

set /test/test "test"

查看更新的节点的值
get -w /test/test
显示test

5、get -s path 查看详细信息

[zk: localhost:2181(CONNECTED) 5] get -s /test/test
test
cZxid = 0x10000001f
ctime = Sat Jul 31 23:37:23 CST 2021
mZxid = 0x100000020
mtime = Sat Jul 31 23:37:45 CST 2021
pZxid = 0x10000001f
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
 

6、删除节点

delete /persistent_sequential_node0000000001

delete /persistent_sequential_node0000000002

ls /

发现节点已删除

7、关闭当前会话

close

8、退出当前客户端连接

quit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值