zookeeper基础命令详解目录
文章目录
- zookeeper基础命令详解目录
- 一、列出所有基础命令
一、列出所有基础命令
先启动一个zookeeper客户端连接zookeeper,如果还没有启动zookeeper集群的参考本文启动之后再做后续操作。
https://blog.csdn.net/weixin_42924400/article/details/144468932
进入命令行界面,输入Help查看有哪些指令
ZooKeeper -server host:port -client-configuration properties-file cmd argsaddWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVEaddauth scheme authcloseconfig [-c] [-w] [-s]connect host:portcreate [-s] [-e] [-c] [-t ttl] path [data] [acl]delete [-v version] pathdeleteall path [-b batch size]delquota [-n|-b] pathget [-s] [-w] pathgetAcl [-s] pathgetAllChildrenNumber pathgetEphemerals pathhistorylistquota pathls [-s] [-w] [-R] pathprintwatches on|offquitreconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]redo cmdnoremovewatches path [-c|-d|-a] [-l]set [-s] [-v version] path datasetAcl [-s] [-v version] [-R] path aclsetquota -n|-b val pathstat [-w] pathsync pathversion
Command not found: Command not found help
主要学习几个指令:
create [-s] [-e] [-c] [-t ttl] path [data] [acl]
delete [-v version] path
deleteall path [-b batch size]
get [-s] [-w] path
quit
set [-s] [-v version] path data
stat [-w] path
ls [-s] [-w] [-R] path
1.create [-s] [-e] [-c] [-t ttl] path [data] [acl]
创建节点(-e 临时节点(重启或者超时就消失 -s 有序序列))
[zk: localhost:2181(CONNECTED) 0] create -s /testseq 111
Created /testseq0000000002
[zk: localhost:2181(CONNECTED) 1] create -s /testseq 111
Created /testseq0000000003
[zk: localhost:2181(CONNECTED) 2] create -s /testseq 111
Created /testseq0000000004
[zk: localhost:2181(CONNECTED) 3] create -s /testseq 111
Created /testseq0000000005
[zk: localhost:2181(CONNECTED) 4] create -s /testseq 111
Created /testseq0000000006
[zk: localhost:2181(CONNECTED) 5] create -s /testseq 111
Created /testseq0000000007
[zk: localhost:2181(CONNECTED) 6] create -s /testseq 111
Created /testseq0000000008
[zk: localhost:2181(CONNECTED) 7] create -s /testseq 111
Created /testseq0000000009
[zk: localhost:2181(CONNECTED) 8]
此时可以发现节点名称是有序递增,且cZid也是有序递增,可以用于追溯分布式环境的事件顺序
[zk: localhost:2181(CONNECTED) 8] create -e /testtemp aaa
Created /testtemp
[zk: localhost:2181(CONNECTED) 9]
关闭zkCli之后,临时节点消失
2.delete [-v version] path
[zk: localhost:2181(CONNECTED) 0] delete /testseq0000000002
[zk: localhost:2181(CONNECTED) 1]
testseq0000000002被删除消失