共计 1853 个字符,预计需要花费 5 分钟才能阅读完成。
本地搭建
单机版
zoo.cfg 配置文件
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=IP1:2888:3888
集群版
zoo.cfg 配置文件
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=IP1:2888:3888
server.2=IP2:2888:3888
server.3=IP3:2888:3888
start
sh %ZK_HOME%/bin/zkCli.sh start
check server status
telnet ip:port
Docker 版
- docker-compose.yml
version: '3.1'
services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
- start container
docker-compose up -d
client script
client connect server
sh %ZK_HOME%/bin/zkCli.sh -server ip:port
# or. connect to the local server by default.
sh %ZK_HOME%/bin/zkCli.sh
list all command
help
#out
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
delquota [-n|-b] path
get [-s] [-w] path
getAcl [-s] path
history
listquota path
ls [-s] [-w] [-R] path
ls2 path [watch]
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]
rmr path
set [-s] [-v version] path data
setAcl [-s] [-v version] [-R] path acl
setquota -n|-b val path
stat [-w] path
sync path
create
create -s -e path data acl
create /zk-book 123
- -s , -e:表示顺序或临时结点。默认情况下, 不添加 -s -e, 代表创建的是持久结点。
- acl:用于进行权限控制
ls
ls [-s] [-w] [-R] path
ls /
ls 只会列出当前目录下的子节点。
get:get data
get [-s] [-w] path
get -s /zk-book
# out
123
cZxid = 0x4
ctime = Sat Oct 26 00:46:44 UTC 2019
mZxid = 0x4
mtime = Sat Oct 26 00:46:44 UTC 2019
pZxid = 0x4
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 3
numChildren = 0
get /zk-book
#out
123
set:update data
set [-s] [-v version] path data
set -s /zk-book asdasdas
#out
cZxid = 0x4
ctime = Sat Oct 26 00:46:44 UTC 2019
mZxid = 0x8
mtime = Sat Oct 26 01:05:37 UTC 2019
pZxid = 0x4
cversion = 0
dataVersion = 4
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 16
numChildren = 0
set /zk-book qweqweasdas
delete
delete [-v version] path
delete /zk-book
想要删除该元素,子节点必须不为空。
正文完