“ZooKeeper”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第74行: 第74行:
 
Znode 改变时,会通知监听当前 Znode 的客户端
 
Znode 改变时,会通知监听当前 Znode 的客户端
 
[[文件:ZooKeeper监听通知.png|无|缩略图|800x800像素]]
 
[[文件:ZooKeeper监听通知.png|无|缩略图|800x800像素]]
 +
 +
=== ZooKeeper 常用命令 ===
 +
 +
==== 启动命令行客户端 ====
 +
 +
 +
未指定 host:port 默认连接本地 ZooKeeper 服务<syntaxhighlight lang="shell-session">
 +
root@ca09cd8f59b4:/opt/zookeeper/bin# ./zkCli.sh
 +
Connecting to localhost:2181
 +
......
 +
[zk: localhost:2181(CONNECTED) 0]
 +
</syntaxhighlight>
 +
 +
 +
指定 host:port 连接指定 ZooKeeper 服务<syntaxhighlight lang="shell-session">
 +
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]
 +
</syntaxhighlight>
 +
 +
 +
 +
==== 查询 ====
 +
 +
 +
查询当前节点下的全部子节点
 +
 +
ls 节点名称<syntaxhighlight lang="shell-session">
 +
[zk: localhost:2181(CONNECTED) 0] ls /
 +
[zookeeper]
 +
[zk: localhost:2181(CONNECTED) 1]
 +
</syntaxhighlight>查询当前节点下的数据<syntaxhighlight lang="shell-session">
 +
[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]
 +
 +
</syntaxhighlight>查询结果第一行是数据
 +
 +
ctime (create time)是创建时间
 +
 +
mtime(modify time)是修改时间

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

官网

https://zookeeper.apache.org/


ZooKeeper 介绍

引言

注册中心

配置集中管理

集群管理

分布式锁、分布式任务

队列的管理


ZooKeeper 介绍

ZooKeeper 本身是 Hadoop 生态圈中的一个组件,ZooKeeper强大的功能,在 Java 分布式架构中,也会频繁地使用到 ZooKeeper。

Zoo Keeper

Hbase 鲸鱼

Hive 蜜蜂

Hadoop 大象

ZooKeeper 就是一个文件系统+监听通知机制


ZooKeeper 安装

ZooKeeper 架构

ZooKeeper 架构图

每一个节点都被称为 Znode;

每一个 Znode 中都可以存储数据,没有目录和文件之分;

节点名称是不允许重复的(不允许在同一个节点下出现名字相同的子节点);

ZooKeeper 架构.png



Znode 类型

四种 Znode

持久节点:

永久的保存在你的 ZooKeeper

持久有序节点:

永久的保存在你的 ZooKeeper,它会给节点添加一个有序的序号。/xx -> /xx00000001

临时节点:

当存储的客户端和 ZooKeeper 服务断开连接时,这个临时节点自动删除

临时有序节点:

当存储的客户端和 ZooKeeper 服务断开连接时,这个临时节点自动删除,它会给节点添加一个有序的序号。/xx -> /xx00000001


ZooKeeper 的监听通知机制

客户端可以去监听 ZooKeeper 中的 Znode 节点。

Znode 改变时,会通知监听当前 Znode 的客户端

ZooKeeper监听通知.png

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)是修改时间