有些事不是努力就可以改变的,五十块的人民币设计的再好看,也没有一百块的招人喜欢。
前言
由于公司年底要更换办公地点,所以最近投了一下简历,发现面试官现在很喜欢问dubbo
、zookeeper
和高并发等。由于公司没有使用dubbo
,只知道dubbo
是一个远程服务调用的分布式框架,zookeeper
为分布式应用程序协调服务。因此,本周查阅资料整理下zookeeper
学习笔记。
安装zookeeper
安装参考链接
基础命令操作
启动zk服务
./zkServer.sh start
[root@localhost bin]# ./zkServer.shZooKeeper JMX enabled by defaultUsing config: /usr/home/zookeeper-3.4.11/bin/../conf/zoo.cfgUsage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}# 提示要以./zkCli.sh start 启动zk./zkCli.sh start 复制代码
查看zk的运行状态
./zkServer.sh status
由于我已经配置了zk
的集群,所以此处显示状态为leader
[root@localhost bin]# ./zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /usr/home/zookeeper-3.4.11/bin/../conf/zoo.cfgMode: leader复制代码
客户端链接zk
[root@localhost bin]# ./zkCli.sh ......WatchedEvent state:SyncConnected type:None path:null[zk: localhost:2181(CONNECTED) 0]复制代码
help 查看客户端帮助命令
help
[zk: localhost:2181(CONNECTED) 0] helpZooKeeper -server host:port cmd args stat path [watch] set path data [version] ls path [watch] delquota [-n|-b] path ls2 path [watch] setAcl path acl setquota -n|-b val path history redo cmdno printwatches on|off delete path [version] sync path listquota path rmr path get path [watch] create [-s] [-e] path data acl addauth scheme auth quit getAcl path close connect host:port[zk: localhost:2181(CONNECTED) 1] 复制代码
ls 查看
ls
查看命令(niocoder
是我测试集群创建的节点,默认只有zookeeper
一个节点)
[zk: localhost:2181(CONNECTED) 1] ls /[niocoder, zookeeper][zk: localhost:2181(CONNECTED) 2] ls /zookeeper [quota][zk: localhost:2181(CONNECTED) 4] ls /zookeeper/quota[]复制代码
get 获取节点数据和更新信息
get
内容为空- cZxid :创建节点的id
- ctime : 节点的创建时间
- mZxid :修改节点的id
- mtime :修改节点的时间
- pZxid :子节点的id
- cversion : 子节点的版本
- dataVersion : 当前节点数据的版本
- aclVersion :权限的版本
- ephemeralOwner :判断是否是临时节点
- dataLength : 数据的长度
- numChildren :子节点的数量
[zk: localhost:2181(CONNECTED) 7] get /zookeeper #下面空行说明节点内容为空cZxid = 0x0ctime = Thu Jan 01 00:00:00 UTC 1970mZxid = 0x0mtime = Thu Jan 01 00:00:00 UTC 1970pZxid = 0x0cversion = -1dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 0numChildren = 1[zk: localhost:2181(CONNECTED) 8]复制代码
stat 获得节点的更新信息
stat
[zk: localhost:2181(CONNECTED) 8] stat /zookeepercZxid = 0x0ctime = Thu Jan 01 00:00:00 UTC 1970mZxid = 0x0mtime = Thu Jan 01 00:00:00 UTC 1970pZxid = 0x0cversion = -1dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 0numChildren = 1复制代码
ls2 ls命令和stat命令的整合
ls2
[zk: localhost:2181(CONNECTED) 10] ls2 /zookeeper[quota]cZxid = 0x0ctime = Thu Jan 01 00:00:00 UTC 1970mZxid = 0x0mtime = Thu Jan 01 00:00:00 UTC 1970pZxid = 0x0cversion = -1dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 0numChildren = 1[zk: localhost:2181(CONNECTED) 11] 复制代码
create 创建节点
create [-s] [-e] path data acl
可以注意一下各个版本的变化
#创建merryyou节点,节点的内容为merryyou[zk: localhost:2181(CONNECTED) 1] create /merryyou merryyouCreated /merryyou#获得merryyou节点内容[zk: localhost:2181(CONNECTED) 3] get /merryyoumerryyoucZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x200000004mtime = Sat Jun 02 14:20:06 UTC 2018pZxid = 0x200000004cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 0复制代码
create -e 创建临时节点
create -e
#创建临时节点[zk: localhost:2181(CONNECTED) 4] create -e /merryyou/temp merryyouCreated /merryyou/temp[zk: localhost:2181(CONNECTED) 5] get /merryyoumerryyoucZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x200000004mtime = Sat Jun 02 14:20:06 UTC 2018pZxid = 0x200000005cversion = 1dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 1[zk: localhost:2181(CONNECTED) 6] get /merryyou/tempmerryyoucZxid = 0x200000005ctime = Sat Jun 02 14:22:24 UTC 2018mZxid = 0x200000005mtime = Sat Jun 02 14:22:24 UTC 2018pZxid = 0x200000005cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x2000000d4500000dataLength = 8numChildren = 0[zk: localhost:2181(CONNECTED) 7] #断开重连之后,临时节点自动消失WATCHER::WatchedEvent state:SyncConnected type:None path:null#因为默认的心跳机制,此时查询临时节点还存在[zk: localhost:2181(CONNECTED) 0] ls /merryyou[temp]#再次查询,临时节点消失[zk: localhost:2181(CONNECTED) 1] ls /merryyou[][zk: localhost:2181(CONNECTED) 2] 复制代码
create -s 创建顺序节点 自动累加
create -s
# 创建顺序节点,顺序节点会自动累加[zk: localhost:2181(CONNECTED) 2] create -s /merryyou/sec seqCreated /merryyou/sec0000000001[zk: localhost:2181(CONNECTED) 3] create -s /merryyou/sec seqCreated /merryyou/sec0000000002 复制代码
set path data [version] 修改节点
[zk: localhost:2181(CONNECTED) 6] get /merryyoumerryyoucZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x200000004mtime = Sat Jun 02 14:20:06 UTC 2018pZxid = 0x200000009cversion = 4dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 2# 修改节点内容为new-merryyou[zk: localhost:2181(CONNECTED) 7] set /merryyou new-merryyoucZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x20000000amtime = Sat Jun 02 14:29:23 UTC 2018pZxid = 0x200000009cversion = 4dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 12numChildren = 2#再次查询,节点内容已经修改[zk: localhost:2181(CONNECTED) 8] get /merryyounew-merryyoucZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x20000000amtime = Sat Jun 02 14:29:23 UTC 2018pZxid = 0x200000009cversion = 4dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 12numChildren = 2#set 根据版本号更新 dataVersion 乐观锁[zk: localhost:2181(CONNECTED) 9] set /merryyou test-merryyou 1cZxid = 0x200000004ctime = Sat Jun 02 14:20:06 UTC 2018mZxid = 0x20000000bmtime = Sat Jun 02 14:31:30 UTC 2018pZxid = 0x200000009cversion = 4dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 13numChildren = 2#因为数据的版本号已经修改为2 再次使用版本号1修改节点提交错误[zk: localhost:2181(CONNECTED) 10] set /merryyou test-merryyou 1version No is not valid : /merryyou复制代码
delete path [version] 删除节点
[zk: localhost:2181(CONNECTED) 13] delete /merryyou/sec000000000sec0000000001 sec0000000002[zk: localhost:2181(CONNECTED) 13] delete /merryyou/sec0000000001[zk: localhost:2181(CONNECTED) 14] ls /merryyou[sec0000000002][zk: localhost:2181(CONNECTED) 15] #版本号操作与set类似 version复制代码
watcher通知机制
关于watcher
机制大体的理解可以为,当每个节点发生变化,都会触发watcher
事件,类似于mysql
的触发器。zk
中 watcher
是一次性的,触发后立即销毁。可以参考
stat path [watch]
设置watch事件get path [watch]
设置watch事件- 子节点创建和删除时触发watch事件,子节点修改不会触发该事件
stat path [watch] 设置watch事件
#添加watch 事件[zk: localhost:2181(CONNECTED) 18] stat /longfei watchNode does not exist: /longfei#创建longfei节点时触发watcher事件[zk: localhost:2181(CONNECTED) 19] create /longfei testWATCHER::WatchedEvent state:SyncConnected type:NodeCreated path:/longfeiCreated /longfei复制代码
get path [watch] 设置watch事件
#使用get命令添加watch事件[zk: localhost:2181(CONNECTED) 20] get /longfei watchtestcZxid = 0x20000000ectime = Sat Jun 02 14:43:15 UTC 2018mZxid = 0x20000000emtime = Sat Jun 02 14:43:15 UTC 2018pZxid = 0x20000000ecversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 4numChildren = 0#修改节点触发watcher事件[zk: localhost:2181(CONNECTED) 21] set /longfei new_testWATCHER::WatchedEvent state:SyncConnected type:NodeDataChanged path:/longfeicZxid = 0x20000000ectime = Sat Jun 02 14:43:15 UTC 2018mZxid = 0x20000000fmtime = Sat Jun 02 14:45:06 UTC 2018pZxid = 0x20000000ecversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 0[zk: localhost:2181(CONNECTED) 22] #删除触发watcher事件[zk: localhost:2181(CONNECTED) 23] get /longfei watchnew_testcZxid = 0x20000000ectime = Sat Jun 02 14:43:15 UTC 2018mZxid = 0x20000000fmtime = Sat Jun 02 14:45:06 UTC 2018pZxid = 0x20000000ecversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 0[zk: localhost:2181(CONNECTED) 24] delete /longfeiWATCHER::WatchedEvent state:SyncConnected type:NodeDeleted path:/longfei[zk: localhost:2181(CONNECTED) 25] 复制代码
ACL权限控制
ZK的节点有5种操作权限:CREATE
、READ
、WRITE
、DELETE
、ADMIN
也就是 增、删、改、查、管理权限,这5种权限简写为crwda
(即:每个单词的首字符缩写)。 注:这5种权限中,delete是指对子节点的删除权限,其它4种权限指对自身节点的操作权限
身份的认证有4种方式:
world
:默认方式,相当于全世界都能访问auth
:代表已经认证通过的用户(cli中可以通过addauth digest user:pwd 来添加当前上下文中的授权用户)digest
:即用户名:密码这种方式认证,这也是业务系统中最常用的ip
:使用Ip地址认证
使用[scheme:id:permissions]
来表示acl权限
getAcl:获取某个节点的acl权限信息
#获取节点权限信息默认为 world:cdrwa任何人都可以访问[zk: localhost:2181(CONNECTED) 34] getAcl /merryyou'world,'anyone: cdrwa[zk: localhost:2181(CONNECTED) 35] 复制代码
setAcl 设置权限
[zk: localhost:2181(CONNECTED) 35] create /merryyou/test testCreated /merryyou/test[zk: localhost:2181(CONNECTED) 36] getAcl /merryyou/test'world,'anyone: cdrwa#设置节点权限 crwa 不允许删除[zk: localhost:2181(CONNECTED) 37] setAcl /merryyou/test world:anyone:crwacZxid = 0x200000018ctime = Sat Jun 02 16:18:18 UTC 2018mZxid = 0x200000018mtime = Sat Jun 02 16:18:18 UTC 2018pZxid = 0x200000018cversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 4numChildren = 0#查询刚才设置的acl权限信息 crwa 没有删除权限[zk: localhost:2181(CONNECTED) 38] getAcl /merryyou/test'world,'anyone: crwa[zk: localhost:2181(CONNECTED) 39] [zk: localhost:2181(CONNECTED) 39] create /merryyou/test/abc abcCreated /merryyou/test/abc#删除子节点的时候提交权限不足[zk: localhost:2181(CONNECTED) 40] delete /merryyou/test/abcAuthentication is not valid : /merryyou/test/abc#设置节点的权限信息为rda[zk: localhost:2181(CONNECTED) 41] setAcl /merryyou/test world:anyone:rda cZxid = 0x200000018ctime = Sat Jun 02 16:18:18 UTC 2018mZxid = 0x200000018mtime = Sat Jun 02 16:18:18 UTC 2018pZxid = 0x20000001acversion = 1dataVersion = 0aclVersion = 2ephemeralOwner = 0x0dataLength = 4numChildren = 1[zk: localhost:2181(CONNECTED) 42] getAcl /merryyou/test'world,'anyone: dra#可以成功删除[zk: localhost:2181(CONNECTED) 43] delete /merryyou/test/abc [zk: localhost:2181(CONNECTED) 46] ls /merryyou/test[][zk: localhost:2181(CONNECTED) 47] #设置节点信息为a admin[zk: localhost:2181(CONNECTED) 47] setAcl /merryyou/test world:anyone:a cZxid = 0x200000018ctime = Sat Jun 02 16:18:18 UTC 2018mZxid = 0x200000018mtime = Sat Jun 02 16:18:18 UTC 2018pZxid = 0x20000001dcversion = 2dataVersion = 0aclVersion = 3ephemeralOwner = 0x0dataLength = 4numChildren = 0#获取 设置都提示权限不足[zk: localhost:2181(CONNECTED) 49] get /merryyou/testAuthentication is not valid : /merryyou/test[zk: localhost:2181(CONNECTED) 50] set /merryyou/test 123Authentication is not valid : /merryyou/test[zk: localhost:2181(CONNECTED) 51] 复制代码
acl Auth 密码明文设置
[zk: localhost:2181(CONNECTED) 53] create /niocoder/merryyou merryyouCreated /niocoder/merryyou#查询默认节点权限信息[zk: localhost:2181(CONNECTED) 54] getAcl /niocoder/merryyou'world,'anyone: cdrwa[zk: localhost:2181(CONNECTED) 55] #使用auth设置节点权限信息[zk: localhost:2181(CONNECTED) 2] setAcl /niocoder/merryyou auth:test:test:cdrwa Acl is not valid : /niocoder/merryyou# 注册test:test 账号密码[zk: localhost:2181(CONNECTED) 3] addauth digest test:test[zk: localhost:2181(CONNECTED) 4] setAcl /niocoder/merryyou auth:test:test:cdrwacZxid = 0x200000020ctime = Sat Jun 02 16:32:08 UTC 2018mZxid = 0x200000020mtime = Sat Jun 02 16:32:08 UTC 2018pZxid = 0x200000020cversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 8numChildren = 0#查询节点权限信息 密码为密文格式[zk: localhost:2181(CONNECTED) 5] getAcl /niocoder/merryyou'digest,'test:V28q/NynI4JI3Rk54h0r8O5kMug=: cdrwa[zk: localhost:2181(CONNECTED) 6] 复制代码
acl digest 密码密文设置
[zk: localhost:2181(CONNECTED) 13] create /names testCreated /names[zk: localhost:2181(CONNECTED) 14] getAcl /names'world,'anyone: cdrwa#使用digest设置节点的权限信息 密码为test密文[zk: localhost:2181(CONNECTED) 15] setAcl /names digest:test:V28q/NynI4JI3Rk54h0r8O5kMug=:cdracZxid = 0x400000006ctime = Sun Jun 03 01:01:17 UTC 2018mZxid = 0x400000006mtime = Sun Jun 03 01:01:17 UTC 2018pZxid = 0x400000006cversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 4numChildren = 0#查询节点权限信息[zk: localhost:2181(CONNECTED) 16] getAcl /names'digest,'test:V28q/NynI4JI3Rk54h0r8O5kMug=: cdra#获取节点信息提示权限不足[zk: localhost:2181(CONNECTED) 5] get /namesAuthentication is not valid : /names# 注册账户[zk: localhost:2181(CONNECTED) 4] addauth digest test:test# 可以正常获取[zk: localhost:2181(CONNECTED) 17] get /names testcZxid = 0x400000006ctime = Sun Jun 03 01:01:17 UTC 2018mZxid = 0x400000006mtime = Sun Jun 03 01:01:17 UTC 2018pZxid = 0x400000006cversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 4numChildren = 0#由于没有设置写权限不能修改节点 w[zk: localhost:2181(CONNECTED) 18] set /names 111Authentication is not valid : /names[zk: localhost:2181(CONNECTED) 19] delete /names[zk: localhost:2181(CONNECTED) 20] 复制代码
acl ip 控制客户端
[zk: localhost:2181(CONNECTED) 22] create /niocoder/ip aaCreated /niocoder/ip[zk: localhost:2181(CONNECTED) 23] get /niocoder/ipaacZxid = 0x40000000actime = Sun Jun 03 01:06:47 UTC 2018mZxid = 0x40000000amtime = Sun Jun 03 01:06:47 UTC 2018pZxid = 0x40000000acversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 2numChildren = 0# 添加ip控制的权限信息[zk: localhost:2181(CONNECTED) 24] setAcl /niocoder/ip ip:192.168.0.68:cdrwacZxid = 0x40000000actime = Sun Jun 03 01:06:47 UTC 2018mZxid = 0x40000000amtime = Sun Jun 03 01:06:47 UTC 2018pZxid = 0x40000000acversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 2numChildren = 0[zk: localhost:2181(CONNECTED) 25] getAcl /niocoder/ip'ip,'192.168.0.68: cdrwa[zk: localhost:2181(CONNECTED) 26] 复制代码
acl super超级管理员
使用super
权限需要修改zkServer.sh
,添加super
管理员,重启zkServer.sh
"-Dzookeeper.DigestAuthenticationProvider.superDigest=test:V28q/NynI4JI3Rk54h0r8O5kMug=" nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.DigestAuthenticationprovider.superDigest=test:V28q/NynI4JI3Rk54h0r8O5kMug=" \ -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &#重启进入zkCli#由于之前设置ip权限,所以不允许访问[zk: localhost:2181(CONNECTED) 2] ls /niocoder/ipAuthentication is not valid : /niocoder/ip#登录账号信息,即为管理员账号[zk: localhost:2181(CONNECTED) 3] addauth digest test:test#正常访问,节点内容为空[zk: localhost:2181(CONNECTED) 4] ls /niocoder/ip[][zk: localhost:2181(CONNECTED) 5] get /niocoder/ipaacZxid = 0x40000000actime = Sun Jun 03 01:06:47 UTC 2018mZxid = 0x40000000amtime = Sun Jun 03 01:06:47 UTC 2018pZxid = 0x40000000acversion = 0dataVersion = 0aclVersion = 1ephemeralOwner = 0x0dataLength = 2numChildren = 0[zk: localhost:2181(CONNECTED) 6] 复制代码
四字命令Four Letter Words
- 使用四字命令需要安装
nc
命令,(yum install nc
)
stat 查看状态信息
[root@localhost bin]# echo stat | nc 192.168.0.68 2181Zookeeper version: 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMTClients: /192.168.0.68:49346[0](queued=0,recved=1,sent=0)Latency min/avg/max: 0/0/4Received: 62Sent: 61Connections: 1Outstanding: 0Zxid: 0x50000000aMode: followerNode count: 10[root@localhost bin]# 复制代码
ruok 查看zookeeper是否启动
[root@localhost bin]# echo ruok | nc 192.168.0.68 2181imok[root@localhost bin]# 复制代码
dump 列出没有处理的节点,临时节点
imok[root@localhost bin]# echo dump | nc 192.168.0.68 2181SessionTracker dump:org.apache.zookeeper.server.quorum.LearnerSessionTracker@29805957ephemeral nodes dump:Sessions with Ephemerals (0):[root@localhost bin]# 复制代码
conf 查看服务器配置
[root@localhost bin]# echo conf | nc 192.168.0.68 2181clientPort=2181dataDir=/usr/home/zookeeper-3.4.11/data/version-2dataLogDir=/usr/home/zookeeper-3.4.11/data/version-2tickTime=2000maxClientCnxns=60minSessionTimeout=4000maxSessionTimeout=40000serverId=2initLimit=10syncLimit=5electionAlg=3electionPort=3888quorumPort=2888peerType=0[root@localhost bin]# 复制代码
cons 显示连接到服务端的信息
[root@localhost bin]# echo cons | nc 192.168.0.68 2181 /192.168.0.68:49354[0](queued=0,recved=1,sent=0)[root@localhost bin]# 复制代码
envi 显示环境变量信息
[root@localhost bin]# echo envi | nc 192.168.0.68 2181Environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMThost.name=localhostjava.version=1.8.0_111java.vendor=Oracle Corporationjava.home=/usr/local/jdk1.8.0_111/jrejava.class.path=/usr/home/zookeeper-3.4.11/bin/../build/classes:/usr/home/zookeeper-3.4.11/bin/../build/lib/*.jar:/usr/home/zookeeper-3.4.11/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/home/zookeeper-3.4.11/bin/../lib/slf4j-api-1.6.1.jar:/usr/home/zookeeper-3.4.11/bin/../lib/netty-3.10.5.Final.jar:/usr/home/zookeeper-3.4.11/bin/../lib/log4j-1.2.16.jar:/usr/home/zookeeper-3.4.11/bin/../lib/jline-0.9.94.jar:/usr/home/zookeeper-3.4.11/bin/../lib/audience-annotations-0.5.0.jar:/usr/home/zookeeper-3.4.11/bin/../zookeeper-3.4.11.jar:/usr/home/zookeeper-3.4.11/bin/../src/java/lib/*.jar:/usr/home/zookeeper-3.4.11/bin/../conf:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/libjava.io.tmpdir=/tmpjava.compiler=os.name=Linuxos.arch=amd64os.version=3.10.0-514.10.2.el7.x86_64user.name=rootuser.home=/rootuser.dir=/usr/home/zookeeper-3.4.11/bin[root@localhost bin]#复制代码
mntr 查看zk的健康信息
[root@localhost bin]# echo mntr | nc 192.168.0.68 2181zk_version 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMTzk_avg_latency 0zk_max_latency 4zk_min_latency 0zk_packets_received 68zk_packets_sent 67zk_num_alive_connections 1zk_outstanding_requests 0zk_server_state followerzk_znode_count 10zk_watch_count 0zk_ephemerals_count 0zk_approximate_data_size 124zk_open_file_descriptor_count 32zk_max_file_descriptor_count 4096[root@localhost bin]# 复制代码
wchs 展示watch的信息
[root@localhost bin]# echo wchs | nc 192.168.0.68 21810 connections watching 0 pathsTotal watches:0[root@localhost bin]# 复制代码
wchc和wchp 显示session的watch信息 path的watch信息
- 需要在 配置
zoo.cfg
文件中添加4lw.commands.whitelist=*
[root@localhost bin]# echo wchc | nc 192.168.0.68 2181wchc is not executed because it is not in the whitelist.[root@localhost bin]# echo wchp | nc 192.168.0.68 2181wchp is not executed because it is not in the whitelist.复制代码
总结
熟悉zookeeper
基础命令操作后,再使用zookeeper
提供的api
或者第三方封装的api
,会感觉一目了然。
推荐文章
???关注微信小程序java架构师历程 上下班的路上无聊吗?还在看小说、新闻吗?不知道怎样提高自己的技术吗?来吧这里有你需要的java架构文章,1.5w+的java工程师都在看,你还在等什么?
复制代码