当前位置:   article > 正文

zookeeper zkCli.sh的基本使用方法_本地zkcli.sh 使用方法

本地zkcli.sh 使用方法

zkCli.sh文件所在位置:
这里写图片描述

1、启动

// -r 表示 在zk集群过半机器无法提供服务的时候,其它机器是否提供只读服务,如果提供,则添加参数-r 
//192.168.179.128 服务器地址
// 5000 单位:毫秒
 ./zkCli.sh -timeout 5000 -r -server 192.168.179.128:2181 
  • 1
  • 2
  • 3
  • 4

执行效果如下:
这里写图片描述

2、常用命令

这里写图片描述

1、查看当前节点列表

[zk: 192.168.179.128:2181(CONNECTED) 2] ls /
[zookeeper]
[zk: 192.168.179.128:2181(CONNECTED) 3] ls /zookeeper
[quota]
  • 1
  • 2
  • 3
  • 4

zk目录结构如下:
这里写图片描述

2、查看节点状态

[zk: 192.168.179.128:2181(CONNECTED) 4] stat /zookeeper
//创建时的事务id
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
//最后一次更新时的事务id
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
//当前节点子节点列表最后一次被修改时的事务id
//引起子节点列表变化的两种情况:删除子节点或者新增子节点
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
//创建该临时节点的事务id
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

3、查看节点数据内容

[zk: 192.168.179.128:2181(CONNECTED) 1] get /zookeeper/quota
  • 1

4、退出

quit
  • 1

5、创建节点

//1111111111111 是节点内容,如果节点没有内容,创建完节点是看不到的
[zk: 192.168.179.128:2181(CONNECTED) 6] create /zookeeper/test1 1111111111111
Created /zookeeper/test1
[zk: 192.168.179.128:2181(CONNECTED) 10] create /zookeeper/test2 
[zk: 192.168.179.128:2181(CONNECTED) 12] ls /zookeeper
[test1, quota]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

6、创建节点并指定限额

//指定test1节点只能有2个子节点
[zk: 192.168.179.128:2181(CONNECTED) 15] setquota -n 2 /zookeeper/test1
Comment: the parts are option -n val 2 path /zookeeper/test1
//添加节点测试
[zk: 192.168.179.128:2181(CONNECTED) 17] create /zookeeper/test1/node1 111
Created /zookeeper/test1/node1
[zk: 192.168.179.128:2181(CONNECTED) 18] create /zookeeper/test1/node2 111
Created /zookeeper/test1/node2
[zk: 192.168.179.128:2181(CONNECTED) 19] create /zookeeper/test1/node3 111 
Created /zookeeper/test1/node3
[zk: 192.168.179.128:2181(CONNECTED) 20] create /zookeeper/test1/node4 111
Created /zookeeper/test1/node4
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

可见,节点限额为2,但能成功创建节点很多个,不会抛出异常:

[zk: 192.168.179.128:2181(CONNECTED) 22] ls /zookeeper/test1 
[node4, node2, node3, node1]
  • 1
  • 2

但日志中会有警告记录,日志位置:
zookeeper-3.4.9/bin/zookeeper.out
内容如下:

jiankunking@ubuntu:~/software/zookeeper-3.4.9/bin$ pwd
/home/jiankunking/software/zookeeper-3.4.9/bin
jiankunking@ubuntu:~/software/zookeeper-3.4.9/bin$ tail zookeeper.out 
2017-03-25 11:19:42,603 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@673] - Established session 0x15b0327cb660005 with negotiated timeout 40000 for client /127.0.0.1:35654
2017-03-25 11:19:42,604 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@666] - Invalid session 0x15b0327cb660004 for client /192.168.179.128:59288, probably expired
2017-03-25 11:19:42,604 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1008] - Closed socket connection for client /192.168.179.128:59288 which had sessionid 0x15b0327cb660004
2017-03-25 11:26:27,423 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@192] - Accepted socket connection from /192.168.179.128:59290
2017-03-25 11:26:27,430 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@928] - Client attempting to establish new session at /192.168.179.128:59290
2017-03-25 11:26:27,432 [myid:] - INFO  [SyncThread:0:ZooKeeperServer@673] - Established session 0x15b0327cb660006 with negotiated timeout 5000 for client /192.168.179.128:59290
2017-03-25 11:33:07,403 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@649] - Got user-level KeeperException when processing sessionid:0x15b0327cb660006 type:create cxid:0x1b zxid:0x14 txntype:-1 reqpath:n/a Error Path:/zookeeper/test2 Error:KeeperErrorCode = NoNode for /zookeeper/test2
2017-03-25 11:33:28,358 [myid:] - WARN  [SyncThread:0:DataTree@301] - Quota exceeded: /zookeeper/test1 count=3 limit=2
2017-03-25 11:33:36,099 [myid:] - WARN  [SyncThread:0:DataTree@301] - Quota exceeded: /zookeeper/test1 count=4 limit=2
2017-03-25 11:33:40,299 [myid:] - WARN  [SyncThread:0:DataTree@301] - Quota exceeded: /zookeeper/test1 count=5 limit=2
jiankunking@ubuntu:~/software/zookeeper-3.4.9/bin$ zookeeper-3.4.9/bin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

7、查看配额信息

[zk: 192.168.179.128:2181(CONNECTED) 23] listquota /zookeeper/test1
//count与bytes值为:-1,表示没有限制
absolute path is /zookeeper/quota/zookeeper/test1/zookeeper_limits
Output quota for /zookeeper/test1 count=2,bytes=-1
Output stat for /zookeeper/test1 count=5,bytes=25
  • 1
  • 2
  • 3
  • 4
  • 5

作者:jiankunking 出处:http://blog.csdn.net/jiankunking

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/302357
推荐阅读
相关标签
  

闽ICP备14008679号