本文主要介绍 ZooKeeper 的常用命令,包括常用命令行命令、ACL 访问控制、四字命令、解析日志和快照等命令。
ZooKeeper 命令行
连接
当集群中的节点已安装 ZooKeeper Client,且 zookeeper-client
为全局环境变量时,可以直接在任意位置使用 zookeeper-client
命令连接当前节点的 ZooKeeper,进入命令行界面。
1 2 3 4 5 6 7 8
| [root@manager ~]# zookeeper-client Connecting to localhost:2181 …………
WATCHER::
WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0]
|
使用 zkCli.sh
进行连接当前节点 ZooKeeper。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| [root@manager bin]# pwd /usr/hdp/3.0.1.0-187/zookeeper/bin [root@manager bin]# ll total 40 -rwxr-xr-x. 1 root root 2155 Nov 23 2019 zkCleanup.sh -rwxr-xr-x. 1 root root 1709 Nov 23 2019 zkCli.sh -rwxr-xr-x. 1 root root 2840 Nov 23 2019 zkEnv.sh -rwxr-xr-x. 1 root root 12 Nov 23 2019 zkServer-initialize.sh -rwxr-xr-x. 1 root root 6822 Nov 23 2019 zkServer.sh -rwxr-xr-x. 1 root root 304 Nov 23 2019 zookeeper-client -rwxr-xr-x. 1 root root 649 Nov 23 2019 zookeeper-server -rwxr-xr-x. 1 root root 650 Nov 23 2019 zookeeper-server-cleanup -rwxr-xr-x. 1 root root 660 Nov 23 2019 zookeeper-server-initialize [root@manager bin]# ./zkCli.sh Connecting to localhost:2181 …………
WATCHER::
WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0]
|
无论是全局变量或 shell 脚本,都可以使用 -server ip:port
的方法连接到某个节点的 ZooKeeper。
1 2 3
| [root@manager ~]# zookeeper-client -server master.bigdata:2181 Connecting to master.bigdata:2181 …………
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [root@manager bin]# pwd /usr/hdp/3.0.1.0-187/zookeeper/bin [root@manager bin]# ll total 40 -rwxr-xr-x. 1 root root 2155 Nov 23 2019 zkCleanup.sh -rwxr-xr-x. 1 root root 1709 Nov 23 2019 zkCli.sh -rwxr-xr-x. 1 root root 2840 Nov 23 2019 zkEnv.sh -rwxr-xr-x. 1 root root 12 Nov 23 2019 zkServer-initialize.sh -rwxr-xr-x. 1 root root 6822 Nov 23 2019 zkServer.sh -rwxr-xr-x. 1 root root 304 Nov 23 2019 zookeeper-client -rwxr-xr-x. 1 root root 649 Nov 23 2019 zookeeper-server -rwxr-xr-x. 1 root root 650 Nov 23 2019 zookeeper-server-cleanup -rwxr-xr-x. 1 root root 660 Nov 23 2019 zookeeper-server-initialize [root@manager bin]# ./zkCli.sh -server master.bigdata:2181 Connecting to master.bigdata:2181 …………
|
退出
在 ZooKeeper Client 命令行交互窗口输入 quit
,退出命令行界面。
1 2 3 4 5
| [zk: localhost:2181(CONNECTED) 0] quit Quitting... 2022-01-03 13:51:57,780 - INFO [main:ZooKeeper@692] - Session: 0x17e03c37bbc0010 closed 2022-01-03 13:51:57,782 - INFO [main-EventThread:ClientCnxn$EventThread@517] - EventThread shut down [root@manager ~]#
|
Znode 基本操作
help 命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [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
|
列出当前节点的子节点
使用 ls path
查看 znode 节点的子节点
1 2 3 4 5 6 7
| [zk: localhost:2181(CONNECTED) 0] ls / [cluster, controller, brokers, zookeeper, hbase-unsecure, dolphinscheduler, admin, isr_change_notification, log_dir_event_notification, hiveserver2, controller_epoch, hiveserver2-leader, kafka-manager, rmstore, atsv2-hbase-unsecure, ambari-metrics-cluster, consumers, latest_producer_id_block, config] [zk: localhost:2181(CONNECTED) 1] ls /brokers [ids, topics, seqid] [zk: localhost:2181(CONNECTED) 2] ls /brokers/ids [1003, 1002, 1001] [zk: localhost:2181(CONNECTED) 3]
|
获取节点存储内容
使用 get path
获取该节点的存储内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [zk: localhost:2181(CONNECTED) 3] get /brokers/ids/1001 {"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://master.bigdata:6667"],"jmx_port":-1,"host":"master.bigdata","timestamp":"1640751404064","port":6667,"version":4} cZxid = 0x60000014a ctime = Wed Dec 29 12:16:44 CST 2021 mZxid = 0x60000014a mtime = Wed Dec 29 12:16:44 CST 2021 pZxid = 0x60000014a cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x17e03c37bbc0001 dataLength = 198 numChildren = 0 [zk: localhost:2181(CONNECTED) 4]
|
获取节点状态
使用 stat path
获取该节点的状态。
1 2 3 4 5 6 7 8 9 10 11 12 13
| [zk: localhost:2181(CONNECTED) 4] stat /brokers/ids/1001 cZxid = 0x60000014a ctime = Wed Dec 29 12:16:44 CST 2021 mZxid = 0x60000014a mtime = Wed Dec 29 12:16:44 CST 2021 pZxid = 0x60000014a cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x17e03c37bbc0001 dataLength = 198 numChildren = 0 [zk: localhost:2181(CONNECTED) 5]
|
创建节点
使用 create path data
创建节点。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [zk: localhost:2181(CONNECTED) 8] create /t1 test1 Created /t1 [zk: localhost:2181(CONNECTED) 9] ls / [cluster, controller, brokers, zookeeper, hbase-unsecure, dolphinscheduler, admin, isr_change_notification, log_dir_event_notification, hiveserver2, controller_epoch, hiveserver2-leader, kafka-manager, rmstore, atsv2-hbase-unsecure, ambari-metrics-cluster, consumers, latest_producer_id_block, config, t1] [zk: localhost:2181(CONNECTED) 10] get /t1 test1 cZxid = 0x600001e24 ctime = Mon Jan 03 14:30:20 CST 2022 mZxid = 0x600001e24 mtime = Mon Jan 03 14:30:20 CST 2022 pZxid = 0x600001e24 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 [zk: localhost:2181(CONNECTED) 11]
|
创建临时节点
使用 create -e path data
创建临时节点。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| [zk: localhost:2181(CONNECTED) 16] create -e /t1/e1 ephemeral_1 Created /t1/e1 [zk: localhost:2181(CONNECTED) 17] get /t1/e1 ephemeral_1 cZxid = 0x600001e2b ctime = Mon Jan 03 14:35:17 CST 2022 mZxid = 0x600001e2b mtime = Mon Jan 03 14:35:17 CST 2022 pZxid = 0x600001e2b cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x17e03c37bbc0014 dataLength = 11 numChildren = 0 [zk: localhost:2181(CONNECTED) 18] quit Quitting... 2022-01-03 14:35:45,076 - INFO [main:ZooKeeper@692] - Session: 0x17e03c37bbc0014 closed 2022-01-03 14:35:45,077 - INFO [main-EventThread:ClientCnxn$EventThread@517] - EventThread shut down
|
重新登录后 e1
节点消失。
1 2 3
| [zk: localhost:2181(CONNECTED) 0] ls /t1 [] [zk: localhost:2181(CONNECTED) 1]
|
创建顺序节点
使用 create -s path data
创建顺序节点。
1 2 3 4 5 6
| [zk: localhost:2181(CONNECTED) 3] create -s /t1/s1 123 Created /t1/s10000000002 [zk: localhost:2181(CONNECTED) 4] create -s /t1/s1 123 Created /t1/s10000000003 [zk: localhost:2181(CONNECTED) 5] ls /t1 [s10000000002, s10000000003]
|
修改节点
使用 set path data
进行修改节点。
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 39 40 41
| [zk: localhost:2181(CONNECTED) 1] create /t2 test2 Created /t2 [zk: localhost:2181(CONNECTED) 3] get /t2 test2 cZxid = 0x600001e99 ctime = Mon Jan 03 16:19:33 CST 2022 mZxid = 0x600001e99 mtime = Mon Jan 03 16:19:33 CST 2022 pZxid = 0x600001e99 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 [zk: localhost:2181(CONNECTED) 4] set /t2 test cZxid = 0x600001e99 ctime = Mon Jan 03 16:19:33 CST 2022 mZxid = 0x600001e9d mtime = Mon Jan 03 16:20:48 CST 2022 pZxid = 0x600001e99 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: localhost:2181(CONNECTED) 5] get /t2 test cZxid = 0x600001e99 ctime = Mon Jan 03 16:19:33 CST 2022 mZxid = 0x600001e9d mtime = Mon Jan 03 16:20:48 CST 2022 pZxid = 0x600001e99 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: localhost:2181(CONNECTED) 6]
|
删除节点
使用 delete path
删除指定路径的节点;
使用 rmr path
可循环删除路径下的节点。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| [zk: localhost:2181(CONNECTED) 8] ls /t2 [] [zk: localhost:2181(CONNECTED) 9] create /t2/a1 a1 Created /t2/a1 [zk: localhost:2181(CONNECTED) 10] create /t2/a2 a2 Created /t2/a2 [zk: localhost:2181(CONNECTED) 11] create /t2/a3 a3 Created /t2/a3 [zk: localhost:2181(CONNECTED) 12] ls /t2 [a1, a2, a3] [zk: localhost:2181(CONNECTED) 13] delete /t2/a1 [zk: localhost:2181(CONNECTED) 14] ls /t2 [a2, a3] [zk: localhost:2181(CONNECTED) 15] rmr /t2 [zk: localhost:2181(CONNECTED) 16] ls / [cluster, controller, brokers, zookeeper, hbase-unsecure, dolphinscheduler, admin, isr_change_notification, log_dir_event_notification, hiveserver2, controller_epoch, hiveserver2-leader, kafka-manager, rmstore, atsv2-hbase-unsecure, ambari-metrics-cluster, consumers, latest_producer_id_block, config, t1] [zk: localhost:2181(CONNECTED) 17]
|
设置节点配额
使用 setquota -n|-b val path
可限制节点的值的长度或其子节点的个数。
- -n 限制节点(包含当前节点)的个数为 val
- -b 限制节点值的长度为 val
- path 要限制的节点路径
限制节点数:
1 2 3 4 5 6 7 8 9 10 11 12 13
| [zk: localhost:2181(CONNECTED) 1] create /t3 test3 Created /t3 [zk: localhost:2181(CONNECTED) 2] setquota -n 2 /t3 Comment: the parts are option -n val 2 path /t3 [zk: localhost:2181(CONNECTED) 3] create /t3/a1 a1 Created /t3/a1 [zk: localhost:2181(CONNECTED) 4] create /t3/a2 a2 Created /t3/a2 [zk: localhost:2181(CONNECTED) 5] create /t3/a3 a3 Created /t3/a3 [zk: localhost:2181(CONNECTED) 6] ls /t3 [a1, a2, a3] [zk: localhost:2181(CONNECTED) 7]
|
超额,不会抛出异常,只是在日志中出现警告信息。
1 2
| 2022-01-03 16:38:33,532 - WARN [CommitProcessor:1:DataTree@302] - Quota exceeded: /t3 count=3 limit=2 2022-01-03 16:38:40,136 - WARN [CommitProcessor:1:DataTree@302] - Quota exceeded: /t3 count=4 limit=2
|
限制节点长度:
1 2 3 4 5 6 7 8 9 10 11
| [zk: localhost:2181(CONNECTED) 9] create /t5 test5 Created /t5 [zk: localhost:2181(CONNECTED) 10] setquota -b 5 /t5 Comment: the parts are option -b val 5 path /t5 [zk: localhost:2181(CONNECTED) 11] create /t5/abc abc Created /t5/abc [zk: localhost:2181(CONNECTED) 12] create /t5/abcdef abcdef Created /t5/abcdef [zk: localhost:2181(CONNECTED) 13] ls /t5 [abcdef, abc] [zk: localhost:2181(CONNECTED) 14]
|
同样,超出显示也不会报错,只是在日志中出现警告信息。
1 2
| 2022-01-03 16:59:33,229 - WARN [CommitProcessor:1:DataTree@348] - Quota exceeded: /t5 bytes=8 limit=5 2022-01-03 16:59:45,076 - WARN [CommitProcessor:1:DataTree@348] - Quota exceeded: /t5 bytes=14 limit=5
|
查看节点配额
1 2 3 4 5 6 7 8 9 10 11
| [zk: localhost:2181(CONNECTED) 7] listquota /t3 absolute path is /zookeeper/quota/t3/zookeeper_limits Output quota for /t3 count=2,bytes=-1 Output stat for /t3 count=4,bytes=11 [zk: localhost:2181(CONNECTED) 8]
[zk: localhost:2181(CONNECTED) 14] listquota /t5 absolute path is /zookeeper/quota/t5/zookeeper_limits Output quota for /t5 count=-1,bytes=5 Output stat for /t5 count=3,bytes=14 [zk: localhost:2181(CONNECTED) 15]
|
删除节点配额
使用 delquota [-n|-b] path
删除配额信息
1 2 3
| [zk: localhost:2181(CONNECTED) 15] delquota -n /t3 [zk: localhost:2181(CONNECTED) 18] delquota -b /t5
|
列出历史操作命令
1 2 3 4 5 6 7 8 9 10 11 12 13
| [zk: localhost:2181(CONNECTED) 22] history 12 - create /t5/abcdef abcdef 13 - ls /t5 14 - listquota /t5 15 - delquota -n /t3 16 - listquota /t3 17 - delquota -b4 /t5 18 - delquota -b /t5 19 - listquota /t5 20 - ls /t3 21 - create /t3/a4 a4 22 - history [zk: localhost:2181(CONNECTED) 23]
|
重新执行 history 中的命令
使用 redo cmdno
可以重新执行history中的命令
1 2 3
| [zk: localhost:2181(CONNECTED) 23] redo 20 [a1, a2, a3, a4] [zk: localhost:2181(CONNECTED) 24]
|
连接其他服务器
使用 connect host:port
可以连接其他服务器。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [zk: localhost:2181(CONNECTED) 0] connect master.bigdata:2181 2022-01-03 17:15:37,507 - INFO [main:ZooKeeper@692] - Session: 0x17e03c37bbc001a closed 2022-01-03 17:15:37,507 - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=master.bigdata:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1c655221 …………
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: master.bigdata:2181(CONNECTED) 1] ls / [cluster, t5, controller, brokers, zookeeper, hbase-unsecure, dolphinscheduler, admin, isr_change_notification, log_dir_event_notification, hiveserver2, controller_epoch, hiveserver2-leader, kafka-manager, rmstore, atsv2-hbase-unsecure, ambari-metrics-cluster, consumers, latest_producer_id_block, config, t1, t3] [zk: master.bigdata:2181(CONNECTED) 2] close 2022-01-03 17:16:08,866 - INFO [main:ZooKeeper@692] - Session: 0x27e03c37a4f000c closed [zk: master.bigdata:2181(CLOSED) 3] 2022-01-03 17:16:08,867 - INFO [main-EventThread:ClientCnxn$EventThread@517] - EventThread shut down
[zk: master.bigdata:2181(CLOSED) 3] quit Quitting... [root@manager bin]#
|
ACL 访问控制
概述
Zookeeper类似于unix文件系统,节点类比文件,客户端可以删除节点,创建节点,修改节点。Zookeeper可以使用ACL(access control list)访问控制列表来对节点的权限进行控制。
acl 权限控制使用:scheme id permission 来标志,主要涵盖三个方面:
- 权限模式(scheme):授权的策略。
- 权限对象(id):授权的对象。
- 权限(permission):授予的权限。
权限模式种类
模式 |
描述 |
world |
这种模式方法的授权对象只有一个anyone,代表登录到服务器的所有客户端都能对该节点执行某种权限 |
ip |
对连接的客户端使用IP地址认证方式进行认证 |
auth |
使用以添加认证的用户进行认证 |
digest |
使用 用户:密码方式验证 |
权限的类型
类型 |
ACL简写 |
描述 |
read |
r |
读取节点及显示子节点列表的权限 |
write |
w |
设置节点数据的权限 |
create |
c |
创建子节点的权限 |
delete |
d |
删除子节点的权限 |
admin |
a |
设置该节点ACL权限的权限 |
关于授权的命令
命令 |
用法 |
描述 |
getAcl |
getAcl path |
读取节点的 ACL |
setAcl |
setAcl path acl |
设置节点的 ACL |
create |
create path data acl |
创建节点时设置 ACL |
addAuth |
addAuth scheme auth |
添加认证用户,类似于登录操作 |
示例
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 39 40 41 42 43 44 45 46 47 48 49 50
| [zk: localhost:2181(CONNECTED) 4] create /test/ta t1 Created /test/ta [zk: localhost:2181(CONNECTED) 5] getAcl /test/ta 'world,'anyone : cdrwa [zk: localhost:2181(CONNECTED) 6] [zk: localhost:2181(CONNECTED) 6] setAcl /test/ta world:anyone:cdwa cZxid = 0x800000093 ctime = Tue Mar 22 15:38:03 CST 2022 mZxid = 0x800000093 mtime = Tue Mar 22 15:38:03 CST 2022 pZxid = 0x800000093 cversion = 0 dataVersion = 0 aclVersion = 1 ephemeralOwner = 0x0 dataLength = 2 numChildren = 0 [zk: localhost:2181(CONNECTED) 7] getAcl /test/ta 'world,'anyone : cdwa [zk: localhost:2181(CONNECTED) 8] get /test/ta Authentication is not valid : /test/ta [zk: localhost:2181(CONNECTED) 9] [zk: localhost:2181(CONNECTED) 9] setAcl /test/ta world:anyone:cdrwa cZxid = 0x800000093 ctime = Tue Mar 22 15:38:03 CST 2022 mZxid = 0x800000093 mtime = Tue Mar 22 15:38:03 CST 2022 pZxid = 0x800000093 cversion = 0 dataVersion = 0 aclVersion = 2 ephemeralOwner = 0x0 dataLength = 2 numChildren = 0 [zk: localhost:2181(CONNECTED) 10] get /test/ta t1 cZxid = 0x800000093 ctime = Tue Mar 22 15:38:03 CST 2022 mZxid = 0x800000093 mtime = Tue Mar 22 15:38:03 CST 2022 pZxid = 0x800000093 cversion = 0 dataVersion = 0 aclVersion = 2 ephemeralOwner = 0x0 dataLength = 2 numChildren = 0 [zk: localhost:2181(CONNECTED) 11]
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| [zk: localhost:2181(CONNECTED) 16] create /test2 t2 Created /test2 [zk: localhost:2181(CONNECTED) 18] [zk: localhost:2181(CONNECTED) 18] addauth digest hdfs:123456 [zk: localhost:2181(CONNECTED) 19] setAcl /test2 auth:hdfs:cdrwa cZxid = 0x800000099 ctime = Tue Mar 22 15:46:58 CST 2022 mZxid = 0x800000099 mtime = Tue Mar 22 15:46:58 CST 2022 pZxid = 0x800000099 cversion = 0 dataVersion = 0 aclVersion = 1 ephemeralOwner = 0x0 dataLength = 2 numChildren = 0 [zk: localhost:2181(CONNECTED) 20] [zk: localhost:2181(CONNECTED) 20] getAcl /test2 'digest,'hdfs:w071ZtmzC5+0fMHyY6QQSDnW3YY= : cdrwa [zk: localhost:2181(CONNECTED) 21]
|
四字命令
在配置文件 zoo.cfg
添加如下配置:
1
| 4lw.commands.whitelist=*
|
打印服务配置详细信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [root@manager ~]# echo conf | nc 127.0.0.1 2181 clientPort=2181 dataDir=/hadoop/zookeeper/version-2 dataLogDir=/hadoop/zookeeper/version-2 tickTime=3000 maxClientCnxns=60 minSessionTimeout=6000 maxSessionTimeout=60000 serverId=1 initLimit=10 syncLimit=5 electionAlg=3 electionPort=3888 quorumPort=2888 peerType=0 [root@manager ~]#
|
列出连接到此服务器的所有客户端的完整连接/会话详细信息。
1 2 3 4 5 6
| [root@manager80 ~]# echo cons | nc 127.0.0.1 2181 /127.0.0.1:56412[0](queued=0,recved=1,sent=0) /10.180.249.80:36610[1](queued=0,recved=11248,sent=11248,sid=0x200000487520016,lop=PING,est=1648707979813,to=60000,lcxid=0x941,lzxid=0xffffffffffffffff,lresp=180432277,llat=0,minlat=0,avglat=0,maxlat=4) /10.180.249.81:57640[1](queued=0,recved=8882,sent=8884,sid=0x100002b03ce0000,lop=PING,est=1648707956970,to=60000,lcxid=0x7,lzxid=0xffffffffffffffff,lresp=180429864,llat=0,minlat=0,avglat=0,maxlat=10) /10.180.249.81:57642[1](queued=0,recved=9023,sent=9036,sid=0x30000047001000a,lop=PING,est=1648707956983,to=60000,lcxid=0x5a0,lzxid=0xffffffffffffffff,lresp=180440871,llat=0,minlat=0,avglat=0,maxlat=18) /10.180.249.80:36612[1]
|
打印有关服务环境的详细信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [root@manager80 ~]# echo envi |nc 127.0.0.1 2181 Environment: zookeeper.version=3.4.14--1, built on 01/20/2021 05:51 GMT host.name=manager80.bigdata java.version=1.8.0_121 java.vendor=Oracle Corporation java.home=/usr/jdk64/java/jre java.class.path=/usr/hdp/current/zookeeper-server/bin/../build/classes:/usr/hdp/current/zookeeper-server/bin/../build/lib/*.jar:/usr/hdp/current/zookeeper-server/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/hdp/current/zookeeper-server/bin/../lib/slf4j-api-1.7.25.jar:/usr/hdp/current/zookeeper-server/bin/../lib/netty-3.10.6.Final.jar:/usr/hdp/current/zookeeper-server/bin/../lib/log4j-1.2.17.jar:/usr/hdp/current/zookeeper-server/bin/../lib/jline-0.9.94.jar:/usr/hdp/current/zookeeper-server/bin/../lib/audience-annotations-0.5.0.jar:/usr/hdp/current/zookeeper-server/bin/../zookeeper-3.4.14.jar:/usr/hdp/current/zookeeper-server/bin/../src/java/lib/*.jar:/usr/hdp/current/zookeeper-server/conf:/usr/jdk64/java/lib:/usr/share/zookeeper/*:/usr/share/zookeeper/* java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.io.tmpdir=/tmp java.compiler=<NA> os.name=Linux os.arch=amd64 os.version=3.10.0-693.el7.x86_64 user.name=zookeeper user.home=/home/zookeeper user.dir=/home/zookeeper [root@manager ~]#
|
列出服务器的完整详细信息。
1 2 3 4 5 6 7 8 9 10 11
| [root@manager80 ~]# echo srvr |nc 127.0.0.1 2181 Zookeeper version: 3.4.14--1, built on 01/20/2021 05:51 GMT Latency min/avg/max: 0/0/2558 Received: 141894 Sent: 141978 Connections: 10 Outstanding: 0 Zxid: 0x200000513 Mode: follower Node count: 83 [root@manager ~]#
|
列出服务器和连接的客户端的简要详细信息。
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
| [root@manager ~]# echo stat | nc 127.0.0.1 2181 Zookeeper version: 3.4.14--1, built on 01/20/2021 05:51 GMT Clients: /10.180.249.61:33984[1](queued=0,recved=597,sent=597) /127.0.0.1:50258[0](queued=0,recved=1,sent=0) /10.180.249.61:33988[1](queued=0,recved=595,sent=595) /10.180.249.61:33950[1](queued=0,recved=599,sent=599) /10.180.249.61:33976[1](queued=0,recved=595,sent=595) /10.180.249.61:33966[1](queued=0,recved=593,sent=593) /10.180.249.61:33954[1](queued=0,recved=590,sent=590) /10.180.249.61:33982[1](queued=0,recved=590,sent=590) /10.180.249.61:33978[1](queued=0,recved=589,sent=589) /10.180.249.61:33944[1](queued=0,recved=1695,sent=1695) /10.180.249.61:33962[1](queued=0,recved=597,sent=597) /10.180.249.61:33952[1](queued=0,recved=597,sent=597)
Latency min/avg/max: 0/0/4945 Received: 7843 Sent: 7842 Connections: 12 Outstanding: 0 Zxid: 0x200021901 Mode: follower Node count: 378 [root@manager ~]#
|
列出服务器监视的简要信息。
1 2 3 4
| [root@manager80 ~]# echo wchs | nc 127.0.0.1 2181 6 connections watching 15 paths Total watches:43 [root@manager80 ~]#
|
解析日志和快照
1 2 3 4 5 6 7 8 9 10 11 12
| [root@manager80 zookeeper]# cd /usr/hdp/3.0.1.0-187/zookeeper [root@manager80 zookeeper]# ll total 1484 drwxr-xr-x 2 root root 255 Feb 25 16:17 bin lrwxrwxrwx 1 root root 28 Feb 25 16:17 conf -> /etc/zookeeper/3.0.1.0-187/0 drwxr-xr-x 6 root root 4096 Feb 25 16:16 doc drwxr-xr-x 3 root root 18 Feb 25 16:16 etc drwxr-xr-x 2 root root 182 Feb 25 16:16 lib drwxr-xr-x 3 root root 18 Feb 25 16:16 man -rw-r--r-- 1 root root 1515059 Jan 21 2021 zookeeper-3.4.14.jar lrwxrwxrwx 1 root root 20 Feb 25 16:16 zookeeper.jar -> zookeeper-3.4.14.jar [root@manager80 zookeeper]# java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.LogFormatter /hadoop/zookeeper/version-2/log.100000001
|
1 2 3 4 5 6
| cd /usr/hdp/3.0.1.0-187/zookeeper java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.SnapshotFormatter /hadoop/zookeeper/version-2/snapshot.400000044
java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.SnapshotFormatter /hadoop/zookeeper/version-2/snapshot.400000044 | grep count
java -cp zookeeper.jar:lib/* org.apache.zookeeper.server.SnapshotFormatter /hadoop/zookeeper/version-2/snapshot.400000044 | grep /rmstore | wc -l
|
参考资料