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 Command not found: Command not found help
//创建持久化节点node1 [zk: localhost:2181(CONNECTED) 0] create /node1 "123" Created /node1 //查看node1节点属性 [zk: localhost:2181(CONNECTED) 1] get -s /node1 123 cZxid = 0x43 ctime = Wed Jul 29 21:27:31 CST 2020 mZxid = 0x43 mtime = Wed Jul 29 21:27:31 CST 2020 pZxid = 0x43 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 3 numChildren = 0 //创建有序持久化节点 [zk: localhost:2181(CONNECTED) 2] create -s /seqNode1 "seq1" Created /seqNode10000000011 //查看有序持久化节点信息 [zk: localhost:2181(CONNECTED) 3] get -s /seqNode10000000011 seq1 cZxid = 0x44 ctime = Wed Jul 29 21:28:25 CST 2020 mZxid = 0x44 mtime = Wed Jul 29 21:28:25 CST 2020 pZxid = 0x44 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 //创建临时节点 [zk: localhost:2181(CONNECTED) 4] create -s -e /tmpNode1 "tmp" Created /tmpNode10000000012 [zk: localhost:2181(CONNECTED) 5] get -s /tmpNode10000000012 tmp cZxid = 0x45 ctime = Wed Jul 29 21:35:28 CST 2020 mZxid = 0x45 mtime = Wed Jul 29 21:35:28 CST 2020 pZxid = 0x45 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x10029ab39130008 dataLength = 3 numChildren = 0
[zk: localhost:2181(CONNECTED) 13] set /node1 "456" [zk: localhost:2181(CONNECTED) 14] get -w /node1 456 [zk: localhost:2181(CONNECTED) 15] set -v 0 /node1 "234" WATCHER:: WatchedEvent state:SyncConnected type:NodeDataChanged path:/node1 [zk: localhost:2181(CONNECTED) 16] get -w /node1 234
[zk: localhost:2181(CONNECTED) 0] delete /node1 [zk: localhost:2181(CONNECTED) 1] get -s /node1 org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /node1 [zk: localhost:2181(CONNECTED) 4] create /node1 "node1" Created /node1 [zk: localhost:2181(CONNECTED) 5] create /node1/node11 "node11" Created /node1/node11 //使用delete删除存在子节点的节点,删除失败 [zk: localhost:2181(CONNECTED) 6] delete /node1 Node not empty: /node1 [zk: localhost:2181(CONNECTED) 7] get -s /node1 node1 cZxid = 0x4f ctime = Wed Jul 29 21:53:37 CST 2020 mZxid = 0x4f mtime = Wed Jul 29 21:53:37 CST 2020 pZxid = 0x50 cversion = 1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 1 [zk: localhost:2181(CONNECTED) 8] deleteall /node1 [zk: localhost:2181(CONNECTED) 9] get /node1 org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /node1
[zk: localhost:2181(CONNECTED) 17] rmr /node1 The command 'rmr' has been deprecated. Please use 'deleteall' instead.
[zk: localhost:2181(CONNECTED) 19] ls / [a0000000001, b0000000002, c, hadoop, seqNode10000000011, zookeeper] [zk: localhost:2181(CONNECTED) 20] ls -s / [a0000000001, b0000000002, c, hadoop, seqNode10000000011, zookeeper]cZxid = 0x0 ctime = Thu Jan 01 08:00:00 CST 1970 mZxid = 0x0 mtime = Thu Jan 01 08:00:00 CST 1970 pZxid = 0x53 cversion = 22 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 0 numChildren = 6 [zk: localhost:2181(CONNECTED) 21] create /node1 "node1" Created /node1 //当前节点下没有子节点,返回空数组 [zk: localhost:2181(CONNECTED) 22] ls /node1 [] [zk: localhost:2181(CONNECTED) 23] create /node1/node11 "node11" Created /node1/node11 [zk: localhost:2181(CONNECTED) 24] ls /node1 [node11]
[zk: localhost:2181(CONNECTED) 25] stat /node1 cZxid = 0x55 ctime = Wed Jul 29 22:05:16 CST 2020 mZxid = 0x55 mtime = Wed Jul 29 22:05:16 CST 2020 pZxid = 0x56 cversion = 1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 1
[zk: localhost:2181(CONNECTED) 27] get /node1 watch 'get path [watch]' has been deprecated. Please use 'get [-s] [-w] path' instead. node1
//一个窗口监听,新打开一个窗口修改节点数据 [zk: localhost:2181(CONNECTED) 29] get -w /node1 node1 //收到修改信息 [zk: localhost:2181(CONNECTED) 30] WATCHER:: WatchedEvent state:SyncConnected type:NodeDataChanged path:/node1 //另一个窗口修改节点: [zk: localhost:2181(CONNECTED) 0] set /node1 "set node1"
[zk: localhost:2181(CONNECTED) 31] getAcl /node1 'world,'anyone : cdrwa [zk: localhost:2181(CONNECTED) 32] setAcl /node1 world:anyone:drwa [zk: localhost:2181(CONNECTED) 33] create /node1/node2 "node2" Authentication is not valid : /node1/node2 [zk: localhost:2181(CONNECTED) 34] setAcl /node1 world:anyone:cdrwa [zk: localhost:2181(CONNECTED) 35] create /node1/node2 "node2" Created /node1/node2
[zk: localhost:2181(CONNECTED) 8] create /ipNode "ipNode" Created /ipNode [zk: localhost:2181(CONNECTED) 9] get -s /ipNode ipNode cZxid = 0x65 ctime = Wed Jul 29 23:22:23 CST 2020 mZxid = 0x65 mtime = Wed Jul 29 23:22:23 CST 2020 pZxid = 0x65 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 6 numChildren = 0 [zk: localhost:2181(CONNECTED) 10] setAcl /ipNode ip:192.168.16.81:ra [zk: localhost:2181(CONNECTED) 11] get -s /ipNode org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /ipNode
//认证用户 [zk: localhost:2181(CONNECTED) 36] addauth digest qxy:123456 [zk: localhost:2181(CONNECTED) 37] get -s /node1 set node1 cZxid = 0x55 ctime = Wed Jul 29 22:05:16 CST 2020 mZxid = 0x58 mtime = Wed Jul 29 22:31:29 CST 2020 pZxid = 0x5c cversion = 2 dataVersion = 1 aclVersion = 2 ephemeralOwner = 0x0 dataLength = 9 numChildren = 2 //设置认证用户 [zk: localhost:2181(CONNECTED) 38] setAcl /node1 auth:qxy:cdrwa //退出,重新进入 [zk: localhost:2181(CONNECTED) 39] quit WATCHER:: WatchedEvent state:Closed type:None path:null 2020-07-29 22:58:56,574 [myid:] - INFO [main:ZooKeeper@1422] - Session: 0x10029ab39130009 closed 2020-07-29 22:58:56,574 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@524] - EventThread shut down for session: 0x10029ab39130009 //未用户认证,无法获取节点信息 [zk: localhost:2181(CONNECTED) 0] get -s /node1 org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /node1 //认证用户,注意此处密码错误,不会提示错误,但是无法访问节点 [zk: localhost:2181(CONNECTED) 1] addauth digest qxy:123456 [zk: localhost:2181(CONNECTED) 2] get -s /node1 set node1 cZxid = 0x55 ctime = Wed Jul 29 22:05:16 CST 2020 mZxid = 0x58 mtime = Wed Jul 29 22:31:29 CST 2020 pZxid = 0x5c cversion = 2 dataVersion = 1 aclVersion = 3 ephemeralOwner = 0x0 dataLength = 9 numChildren = 2
echo -n <user>:<password> | openssl dgst -binary -sha1 | openssl base64
[root@izbp14najjyuhkvm4qbic7z bin]# echo -n qxy:123456 | openssl dgst -binary -sha1 | openssl base64 hDF4uLZvMJqOX2ekKFa6kSz9HNo=
[zk: localhost:2181(CONNECTED) 5] create /digestNode "digestNode" Created /digestNode [zk: localhost:2181(CONNECTED) 2] setAcl /digestNode digest:qxy:hDF4uLZvMJqOX2ekKFa6kSz9HNo=:cdrwa [zk: localhost:2181(CONNECTED) 3] get /digestNode org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /digestNode [zk: localhost:2181(CONNECTED) 2] setAcl /digestNode digest:qxy:hDF4uLZvMJqOX2ekKFa6kSz9HNo=:cdrwa [zk: localhost:2181(CONNECTED) 3] get /digestNode org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /digestNode [zk: localhost:2181(CONNECTED) 4] getAcl /digestNode Authentication is not valid : /digestNode [zk: localhost:2181(CONNECTED) 5] addauth digest qxy:123456 [zk: localhost:2181(CONNECTED) 6] getAcl /digestNode 'digest,'qxy:hDF4uLZvMJqOX2ekKFa6kSz9HNo= : cdrwa [zk: localhost:2181(CONNECTED) 7] get /digestNode digestNode
END 十期推荐 【251期】面试官:谈谈你对零拷贝的理解~ 【252期】运行时常量池的一道面试题(JDK8环境) 【253期】面试官:熟悉Docker操作吗?说几个常用的Docker命令吧 【254期】面试官:来谈谈微服务组件Feign的工作原理吧 【255期】面试官:Mybatis是如何运用设计模式的? 【256期】面试官常考的 21 条 Linux 命令 【257期】面试官:谈谈你对Java线程安全与不安全的理解 【258期】今日头条的面试题:LRU原理和Redis实现 【259期】面试官:Spring事务失效的场景有哪些?如何解决? 【260期】Java线程池,这篇能让你和面试官聊了半小时 ? ~