zookeeper常见命令详解2

1、version 展示客户端版本

[zkshell: 1] version
ZooKeeper CLI version: 3.6.0-SNAPSHOT-29f9b2c1c0e832081f94d59a6b88709c5f1bb3ca, built on 05/30/2019 09:26 GMT

2、whoami 展示出所有已经添加(addauth)用户的信息

[zkshell: 1] whoami
Auth scheme: User
ip: 127.0.0.1
[zkshell: 2] addauth digest user1:12345
[zkshell: 3] whoami
Auth scheme: User
ip: 127.0.0.1
digest: user1

3、set [-s] [-v version] path data 设置或者更新节点的数据

[zkshell: 50] set /brokers myNewData
  • set -s 设置值的同时并展示znode状态
[zkshell: 51] set -s /quota_test mydata_for_quota_test
	cZxid = 0x110000002d
	ctime = Thu Mar 07 11:19:07 UTC 2019
	mZxid = 0x1100000038
	mtime = Thu Mar 07 11:42:41 UTC 2019
	pZxid = 0x1100000033
	cversion = 3
	dataVersion = 2
	aclVersion = 0
	ephemeralOwner = 0x0
	dataLength = 21
	numChildren = 3
  • -v 设置dataVersion的版本号,如果传入的dataVersion与当前版本号不一致时,zookeeper会拒绝设置值。
[zkshell: 52] set -v 0 /brokers myNewData
[zkshell: 53] set -v 0 /brokers myNewData
	version No is not valid : /brokers

4、close 关闭客户端/session

[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

5、config 展示集群节点配置

[zkshell: 17] config
	server.1=[2001:db8:1:0:0:242:ac11:2]:2888:3888:participant
	server.2=[2001:db8:1:0:0:242:ac11:2]:12888:13888:participant
	server.3=[2001:db8:1:0:0:242:ac11:2]:22888:23888:participant
	version=0

6、connect 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"

# connect a remote server
[zkshell: 5] connect remoteIP:2181

7、removewatches 移除节点的watch

[zkshell: 1] get -w /brokers
	null
[zkshell: 2] removewatches /brokers
	WATCHER::
	WatchedEvent state:SyncConnected type:DataWatchRemoved path:/brokers

8、history 展示最近已经执行过的11个命令

[zkshell: 7] history
	0 - close
	1 - close
	2 - ls /
	3 - ls /
	4 - connect
	5 - ls /
	6 - ll
	7 - history

9、redo 使用数字index 重新执行已经执行过的命令

[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]

10、sync path 在leader和followers 同步节点数据(异步同步 Asynchronous sync)

[zkshell: 14] sync /
[zkshell: 15] Sync is OK

11、quota 份额

  • 一个节点的quota份额被存储在 /zookeeper/quota 节点下;
  • 用户不能对/zookeeper/quota节点下的节点设置quota;包括/zookeeper/quota节点本身;
  • quota 支持软(soft)quota 和硬(hard)quota,当超出设定的值时,软quota依旧可以创建成功,但是会告警,硬quota不会设置成功,会抛出QuotaExceededException异常;
  • 一个节点的quota属性如下:
[zk: localhost:2181(CONNECTED) 6] listquota /test1
absolute path is /zookeeper/quota/test1/zookeeper_limits
quota for /test1 does not exist.
[zk: localhost:2181(CONNECTED) 8] setquota -n 4 /test1
[zk: localhost:2181(CONNECTED) 9] listquota /test1
absolute path is /zookeeper/quota/test1/zookeeper_limits
Output quota for /test1 count=4,bytes=-1=;byteHardLimit=-1;countHardLimit=-1
Output stat for /test1 count=1,bytes=0
[zk: localhost:2181(CONNECTED) 10]
  • 当同时设置软quota和硬quota的时候,硬quota优先性高;
  • 当对一个节点设置quota的时候,如果它的父节点或者子节点已经被设置了quota,则该节点无法设置成功;
[zk: localhost:2181(CONNECTED) 36] setquota -N 3 /test2/li
/test2/li has a parent /test2 which has a quota
  • 在3.7.0版本以及之后的版本中新增该配置检查,启用方式需要在配置文件中新增:
enforceQuota=true
  • 当设置节点数量的时候,节点数量会包括自身,即不能设置为0;
[zk: localhost:2181(CONNECTED) 50] setquota -N 0 /test5
the num quota must be greater than zero
[zk: localhost:2181(CONNECTED) 51]

(1) setquota -n|-b|-N|-B val path 设置份额

  • setquota -n count /path/node 软设置该节点子节点的数量(直属子节点),如果该设置存在,则会更新该设置,该节点必须存在才能设置;这种限制是软限制,如果超出数量,只会警告但是并不会报错;
[zk: localhost:2181(CONNECTED) 4] ls -R /
/
/test1
/zookeeper
/zookeeper/config
/zookeeper/quota
[zk: localhost:2181(CONNECTED) 5] setquota -n 2 /test2
/test2 does not exist.
[zk: localhost:2181(CONNECTED) 6]
[zkshell: 18] setquota -n 2 /quota_test
[zkshell: 19] create /quota_test/child_1
	Created /quota_test/child_1
[zkshell: 20] create /quota_test/child_2
	Created /quota_test/child_2
[zkshell: 21] create /quota_test/child_3
	Created /quota_test/child_3
# Notice:don't have a hard constraint,just log the warning info
	2019-03-07 11:22:36,680 [myid:1] - WARN  [SyncThread:0:DataTree@374] - Quota exceeded: /quota_test count=3 limit=2
	2019-03-07 11:22:41,861 [myid:1] - WARN  [SyncThread:0:DataTree@374] - Quota exceeded: /quota_test count=4 limit=2
  • setquota -b bytes /path/node 软设置该节点数据的长度,如果该设置存在,则会更新该设置,该节点必须存在才能设置;这种限制是软限制,如果超出长度,只会警告但是并不会报错;
# -b to limit the bytes(data length) of one path
[zkshell: 22] setquota -b 5 /brokers
[zkshell: 23] set /brokers "I_love_zookeeper"
# Notice:don't have a hard constraint,just log the warning info
	WARN  [CommitProcWorkThread-7:DataTree@379] - Quota exceeded: /brokers bytes=4206 limit=5
  • setquota -N count /path/node 硬设置该节点子节点的数量,如果该设置存在,则会更新该设置,该节点必须存在才能设置;这种限制是硬限制,如果超出数量,会抛出异常;
[zk: localhost:2181(CONNECTED) 45] setquota -N 3 /test4
[zk: localhost:2181(CONNECTED) 46] create /test4/li
Created /test4/li
[zk: localhost:2181(CONNECTED) 47] create /test4/l2
Created /test4/l2
[zk: localhost:2181(CONNECTED) 48] create /test4/l3
Quota has exceeded : /test4/l3
[zk: localhost:2181(CONNECTED) 49]
  • setquota -B bytes /path/node 硬设置该节点数据的长度,如果该设置存在,则会更新该设置,该节点必须存在才能设置;这种限制是硬限制,如果超出长度,会抛出异常;

(2) listquota path 列出quota信息

zk: localhost:2181(CONNECTED) 51] listquota /test4
absolute path is /zookeeper/quota/test4/zookeeper_limits
Output quota for /test4 count=-1,bytes=-1=;byteHardLimit=-1;countHardLimit=3
Output stat for /test4 count=3,bytes=0
[zk: localhost:2181(CONNECTED) 52]

(3)delquota [-n|-b|-N|-B] path 删除quota

[zkshell: 1] delquota /quota_test
[zkshell: 2] listquota /quota_test
	absolute path is /zookeeper/quota/quota_test/zookeeper_limits
	quota for /quota_test does not exist.
[zkshell: 3] delquota -n /c1
[zkshell: 4] delquota -N /c2
[zkshell: 5] delquota -b /c3
[zkshell: 6] delquota -B /c4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值