zookeeper命令
- conf: 输出相关服务配置的详细信息
- cons: 列出所有连接到服务器的客户端的完全的连接/会话的详细信息
- dump: 列出未经处理的会话和临时节点
- envi: 输出关于服务环境的详细信息
- reqs: 列出未经处理的请求
- ruok: 测试服务是否处于正确状态,如果正常,返回‘imok’,否则不做任何响应
- stat: 输出关于性能和连接的客户端的列表
- wchs: 列出服务器watch的详细信息
- wchc: 通过session列出服务器watch的详细信息,它的输出是一个与watch相关的会话的列表
- wchp: 通过路径列出服务器watch的详细信息,他输出一个session相关的路径
conf
1
~]# echo conf | nc localhost 2181
2
clientPort=2181
3
dataDir=/tmp/zookeeper/node-1/data/version-2
4
dataLogDir=/tmp/zookeeper/node-1/data/version-2
5
tickTime=2000
6
maxClientCnxns=60
7
minSessionTimeout=4000
8
maxSessionTimeout=40000
9
serverId=0
10
initLimit=10
11
syncLimit=5
12
electionAlg=3
13
electionPort=3387
14
quorumPort=2287
15
peerType=0
cons
1
~]# echo cons | nc localhost 2181
2
/0:0:0:0:0:0:0:1:42735[0](queued=0,recved=1,sent=0)
dump
1
~]# echo dump | nc localhost 2181
2
SessionTracker dump:
3
org.apache.zookeeper.server.quorum.LearnerSessionTracker@7ca541a4
4
ephemeral nodes dump:
5
Sessions with Ephemerals (0):
envi
1
~]# echo envi | nc localhost 2181
2
Environment:
3
zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
4
host.name=<NA>
5
java.version=1.8.0_151
6
java.vendor=Oracle Corporation
7
java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre
8
java.class.path=/usr/local/zookeeper-3.4.11/bin/../build/classes:/usr/local/zookeeper-3.4.11/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.11/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.11/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.11/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper-3.4.11/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.11/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.11/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper-3.4.11/bin/../zookeeper-3.4.11.jar:/usr/local/zookeeper-3.4.11/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.11/bin/../conf:
9
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
10
java.io.tmpdir=/tmp
11
java.compiler=<NA>
12
os.name=Linux
13
os.arch=amd64
14
os.version=3.10.0-327.el7.x86_64
15
user.name=root
16
user.home=/root
17
user.dir=/usr/local/zookeeper-3.4.11/bin
reqs
1
~]# echo reqs | nc localhost 2181
ruok
1
~]# echo ruok | nc localhost 2181
2
imok
stat
1
~]# echo stat | nc localhost 2181
2
Zookeeper version: 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
3
Clients:
4
/0:0:0:0:0:0:0:1:42740[0](queued=0,recved=1,sent=0)
5
6
Latency min/avg/max: 0/0/0
7
Received: 8
8
Sent: 7
9
Connections: 1
10
Outstanding: 0
11
Zxid: 0x0
12
Mode: follower
13
Node count: 4
wchs
1
~]# echo wchs | nc localhost 2181
2
0 connections watching 0 paths
3
Total watches:0
wchc
1
~]# echo wchc | nc localhost 2181
2
wchc is not executed because it is not in the whitelist.
wchp
1
~]# echo wchp | nc localhost 2181
2
wchp is not executed because it is not in the whitelist.
zookeeper操作
zookeeper的shell操作
1 | ~]# ./zkCli.sh -server localhost:2181 |
2 | ... |
3 | |
4 | WATCHER:: |
5 | |
6 | WatchedEvent state:SyncConnected type:None path:null |
7 | [zk: localhost:2181(CONNECTED) 0] |
1 | [zk: localhost:2181(CONNECTED) 0] help |
2 | ZooKeeper -server host:port cmd args |
3 | stat path [watch] |
4 | set path data [version] |
5 | ls path [watch] |
6 | delquota [-n|-b] path |
7 | ls2 path [watch] |
8 | setAcl path acl |
9 | setquota -n|-b val path |
10 | history |
11 | redo cmdno |
12 | printwatches on|off |
13 | delete path [version] |
14 | sync path |
15 | listquota path |
16 | rmr path |
17 | get path [watch] |
18 | create [-s] [-e] path data acl |
19 | addauth scheme auth |
20 | quit |
21 | getAcl path |
22 | close |
23 | connect host:port |
24 | [zk: localhost:2181(CONNECTED) 1] ls / |
25 | [zookeeper] |
26 | [zk: localhost:2181(CONNECTED) 2] create /zk MyData #创建一个新的Znode节点 |
27 | Created /zk |
28 | [zk: localhost:2181(CONNECTED) 3] ls / |
29 | [zk, zookeeper] |
30 | [zk: localhost:2181(CONNECTED) 4] get /zk |
31 | MyData |
32 | cZxid = 0x100000002 |
33 | ctime = Tue Jan 23 02:30:37 EST 2018 |
34 | mZxid = 0x100000002 |
35 | mtime = Tue Jan 23 02:30:37 EST 2018 |
36 | pZxid = 0x100000002 |
37 | cversion = 0 |
38 | dataVersion = 0 |
39 | aclVersion = 0 |
40 | ephemeralOwner = 0x0 |
41 | dataLength = 6 |
42 | numChildren = 0 |
43 | |
44 | [zk: localhost:2181(CONNECTED) 6] set /zk jusene12345 |
45 | cZxid = 0x100000002 |
46 | ctime = Tue Jan 23 02:30:37 EST 2018 |
47 | mZxid = 0x100000003 |
48 | mtime = Tue Jan 23 02:33:42 EST 2018 |
49 | pZxid = 0x100000002 |
50 | cversion = 0 |
51 | dataVersion = 1 |
52 | aclVersion = 0 |
53 | ephemeralOwner = 0x0 |
54 | dataLength = 11 |
55 | numChildren = 0 |
56 | [zk: localhost:2181(CONNECTED) 7] get /zk |
57 | jusene12345 |
58 | cZxid = 0x100000002 |
59 | ctime = Tue Jan 23 02:30:37 EST 2018 |
60 | mZxid = 0x100000003 |
61 | mtime = Tue Jan 23 02:33:42 EST 2018 |
62 | pZxid = 0x100000002 |
63 | cversion = 0 |
64 | dataVersion = 1 |
65 | aclVersion = 0 |
66 | ephemeralOwner = 0x0 |
67 | dataLength = 11 |
68 | numChildren = 0 |
69 | |
70 | [zk: localhost:2181(CONNECTED) 8] delete /zk |
71 | [zk: localhost:2181(CONNECTED) 9] ls / |
72 | [zookeeper] |