zookeeper 笔记

启动zkServer

localhost:~ qiqi$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED

// 客户端连接
localhost:~ qiqi$ zkCli -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0] ls/
ZooKeeper -server host:port -client-configuration properties-file cmd args
	addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
	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 [-b batch size]
	delquota [-n|-b|-N|-B] path
	get [-s] [-w] path
	getAcl [-s] path
	getAllChildrenNumber path
	getEphemerals path
	history 
	listquota path
	ls [-s] [-w] [-R] path
	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]
	set [-s] [-v version] path data
	setAcl [-s] [-v version] [-R] path acl
	setquota -n|-b|-N|-B val path
	stat [-w] path
	sync path
	version 
	whoami 
Command not found: Command not found ls/

查看注册中心默认根节点

[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[dubbo, services, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 2] ls
ls [-s] [-w] [-R] path
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[dubbo, services, zookeeper]

有三个 分别是 dubbo, services, zookeeper

新建根节点

[zk: 127.0.0.1:2181(CONNECTED) 4] create /zk_test
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 5] ls /
[dubbo, services, zk_test, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 6] create /zk_test my_data
Node already exists: /zk_test

[zk: 127.0.0.1:2181(CONNECTED) 8] create /zk_test2 my_data
Created /zk_test2
[zk: 127.0.0.1:2181(CONNECTED) 9] ls /
[dubbo, services, zk_test, zk_test2, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 10] get /zk_test2
my_data
[zk: 127.0.0.1:2181(CONNECTED) 11] set /zk_test junk
[zk: 127.0.0.1:2181(CONNECTED) 12] get /zk_test
junk
[zk: 127.0.0.1:2181(CONNECTED) 13] delete /zk_test


[zk: 127.0.0.1:2181(CONNECTED) 15] get /zk_test
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 16] 

退出客户端

[zk: 127.0.0.1:2181(CONNECTED) 16] quit

WATCHER::

WatchedEvent state:Closed type:None path:null

关闭zookeeper服务

localhost:~ qiqi$ zkServer stop
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Stopping zookeeper ... STOPPED

等等

让我在来看一下,刚刚我已经把zkf服务关闭了,现在又重启了,重启之后让我们看一下还有那些节点存在

[zk: 127.0.0.1:2181(CONNECTED) 0] ls
ls [-s] [-w] [-R] path
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[dubbo, services, zk_test2, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 2] get /dubbo
127.0.0.1
[zk: 127.0.0.1:2181(CONNECTED) 3] get /services

[zk: 127.0.0.1:2181(CONNECTED) 4] get /zookeeper

[zk: 127.0.0.1:2181(CONNECTED) 5] 

zk_test2 依然存在, 表名 zk_test2 是一个持久化节点,zk 把节点分为

  • 持久化节点: 节点数据持久化到磁盘
  • 临时节点: 节点生命周期和创建该节点的客户端生命周期保持一致,所有url 节点都是临时节点。(待补充)
  • 有序节点: 在创建的节点后面会增加一个递增的序列,该序列在同一级父节点下是唯一的。(待完善补充…)

由此可知,dubbo , zookeeper, services, zk_test2 都是持久化节点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值