“ZooKeeper”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第8行: 第8行:
  
  
 +
[[ZooKeeper 架构]]
  
=== ZooKeeper 架构 ===
 
  
==== ZooKeeper 架构图 ====
 
每一个节点都被称为 Znode;
 
  
每一个 Znode 中都可以存储数据,没有目录和文件之分;
 
  
节点名称是不允许重复的(不允许在同一个节点下出现名字相同的子节点);
 
[[文件:ZooKeeper 架构.png|无|缩略图|700x700像素]]
 
  
 +
===ZooKeeper 常用命令===
  
 +
====启动命令行客户端连接 ZooKeeper 实例====
  
 
==== Znode 类型 ====
 
四种 Znode
 
 
持久节点:
 
 
永久的保存在你的 ZooKeeper
 
 
持久有序节点:
 
 
永久的保存在你的 ZooKeeper,它会给节点添加一个有序的序号。/xx -> /xx00000001
 
 
临时节点:
 
 
当存储的客户端和 ZooKeeper 服务断开连接时,这个临时节点自动删除
 
 
临时有序节点:
 
 
当存储的客户端和 ZooKeeper 服务断开连接时,这个临时节点自动删除,它会给节点添加一个有序的序号。/xx -> /xx00000001
 
 
 
==== ZooKeeper 的监听通知机制 ====
 
客户端可以去监听 ZooKeeper 中的 Znode 节点。
 
 
Znode 改变时,会通知监听当前 Znode 的客户端
 
[[文件:ZooKeeper监听通知.png|无|缩略图|800x800像素]]
 
 
=== ZooKeeper 常用命令 ===
 
 
==== 启动命令行客户端连接 ZooKeeper 实例 ====
 
  
  
第59行: 第26行:
 
[zk: localhost:2181(CONNECTED) 0]  
 
[zk: localhost:2181(CONNECTED) 0]  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
  
第69行: 第37行:
  
  
 
+
====查询====
==== 查询 ====
 
  
  
第102行: 第69行:
 
mtime(modify time)是修改时间
 
mtime(modify time)是修改时间
  
==== 创建节点 ====
+
====创建节点====
 
create [-s] [-e] Znode名称 Znode数据
 
create [-s] [-e] Znode名称 Znode数据
  

2022年8月16日 (二) 07:33的版本

官网

https://zookeeper.apache.org/


ZooKeeper 介绍、安装


ZooKeeper 架构



ZooKeeper 常用命令

启动命令行客户端连接 ZooKeeper 实例

未指定 host:port 默认连接本地 ZooKeeper 服务

root@ca09cd8f59b4:/opt/zookeeper/bin# ./zkCli.sh
Connecting to localhost:2181
......
[zk: localhost:2181(CONNECTED) 0]


指定 host:port 连接指定 ZooKeeper 服务

root@ca09cd8f59b4:/opt/zookeeper/bin# ./zkCli.sh 192.168.137.201:2121
Connecting to 192.168.137.201:2181
......
[zk: 192.168.137.201:2181(CONNECTED) 0]


查询

查询当前节点下的全部子节点

ls 节点名称

[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1]

查询当前节点下的数据

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

cZxid = 0x0
ctime = Thu Jan 01 00:00:00 UTC 1970
mZxid = 0x0
mtime = Thu Jan 01 00:00:00 UTC 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
[zk: localhost:2181(CONNECTED) 5]

查询结果第一行是数据

ctime (create time)是创建时间

mtime(modify time)是修改时间

创建节点

create [-s] [-e] Znode名称 Znode数据

-s:sequence,有序节点

-e:ephemeral,临时节点

[zk: localhost:2181(CONNECTED) 5] create /qf xxx
Created /qf
[zk: localhost:2181(CONNECTED) 6] ls /
[qf, zookeeper]
[zk: localhost:2181(CONNECTED) 7] get /qf
xxx
cZxid = 0x6
ctime = Tue Aug 16 01:10:18 UTC 2022
mZxid = 0x6
mtime = Tue Aug 16 01:10:18 UTC 2022
pZxid = 0x6
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 3
numChildren = 0
[zk: localhost:2181(CONNECTED) 8]