zookeeper介绍
# zookeeper是什么
高性能分布式数据一致性解决方案。
# 基本概念
- 集群角色
- leader: 负责进行投票的发起和决议,更新系统状态
- follower: 接收客户端请求并想客户端返回结果,在选主过程中参与投票
- observer: 接收客户端连接,将写请求转发给leader,但不参与投票,只同步leader的状态,observer的目的是为了扩展系统,提高读取速度
- 会话: 客户端与服务器的链接
- 节点
- 临时节点: 在会话断开后删除
- 永久节点: 在会话断开后不会删除
- 版本
- version: 当前节点数据变更版本号
- cversion: 当前节点子节点版本号
- acersion: 当前节点ACL变更版本号
- watcher: 注册相关数据变更的client就是一个watcher。当数据变更时,server将数据变更事件通知给对应数据的watcher
- ACL权限控制:
- CREATE: 节点创建
- READ: 节点数据读取
- WRITE: 节点数据更新
- DELETE: 节点数据删除
- ADMIN: 节点数据ACL管理
# zkCli基本使用
# 连接zk服务器,默认连接127.0.0.1:2181
bash zkCli.sh
e.zookeeper.ZooKeeperMain$MyWatcher@41906a77
Welcome to ZooKeeper!
2019-02-17 17:12:43,137 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-02-17 17:12:43,259 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-02-17 17:12:43,281 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x10000b9659a0001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] help # 帮助文档
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Last Updated: 2024/04/23, 01:30:37