0 课程地址
https://coding.imooc.com/lesson/201.html#mid=12712
1 重点关注
1.1 执行前准备
zk四字命令 Four Letter Words
zk可以通过安自身提供的简写命令来和服务器进行交互
- 安装nc
需要使用到 nc命令,安装: yum install nc
- 四字命令官方文档
百度zookeeper->Documention->版本->左侧Admin & Ops->Administrator's Guide->搜索four Letter
可以看到4字命令
- 四字命令格式
echo [command] | nc [ip] [port]
1.2 常见四字命令
- [stat] 查看zk的状态信息,以及是否mode,集群或单例
echo stat | nc localhost 2181
[root@localhost ~]# echo stat | nc localhost 2181 Zookeeper version: 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT Clients: /0:0:0:0:0:0:0:1:44292[0](queued=0,recved=1,sent=0) /127.0.0.1:53684[1](queued=0,recved=124,sent=124) Latency min/avg/max: 0/0/15 Received: 133 Sent: 132 Connections: 2 Outstanding: 0 Zxid: 0x62 Mode: standalone --说明单例模式,不是集群 Node count: 14
- [ruok] 查看当前zkserver是否启动,返回 imok或Ncat
echo ruok | nc localhost 2181
imok 启动状态,ncat没有猫,未启动
- [dump] 列出未经处理的会话和临时节点
echo dump | nc localhost 2181
[root@localhost ~]# echo dump | nc localhost 2181 SessionTracker dump: Session Sets (3): 0 expire at Thu Jan 08 09:37:50 CST 1970: 0 expire at Thu Jan 08 09:38:00 CST 1970: 1 expire at Thu Jan 08 09:38:10 CST 1970: --1个开启的会话 0x100244d3cf10000 ephemeral nodes dump: Sessions with Ephemerals (1): --1个临时节点 0x100244d3cf10000: /names/temp-dump
- [conf] 查看zk服务端配置
echo conf | nc localhost 2181
[root@localhost ~]# echo conf | nc localhost 2181 clientPort=2181 --端口 dataDir=/usr/local/zookeeper/dataDir/version-2 --数据路径 dataLogDir=/usr/local/zookeeper/dataLogDir/version-2 --日志路径 tickTime=2000 --执行单元 2s maxClientCnxns=60 minSessionTimeout=4000 maxSessionTimeout=40000 serverId=0 [root@localhost ~]#
- [cons]查看zk连接到服务器的客户端信息
echo cons | nc localhost 2181
[root@localhost ~]# echo cons | nc localhost 2181 /0:0:0:0:0:0:0:1:44288[0](queued=0,recved=1,sent=0) /127.0.0.1:53684[1](queued=0,recved=56,sent=56,sid=0x100244d3cf10000,lop=PING,est=1708902855675,to=30000,lcxid=0x3,lzxid=0x62,lresp=609658541,llat=0,minlat=0,avglat=0,maxlat=15)
- [envi]环境变量
echo envi | nc localhost 2181
[root@localhost ~]# echo envi | nc localhost 2181 Environment: zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT host.name=localhost java.version=1.8.0_202 java.vendor=Oracle Corporation java.home=/usr/jdk8/jre java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.11.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar 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-1160.el7.x86_64 user.name=root user.home=/root user.dir=/usr/local/zookeeper/bin [root@localhost ~]#
2 课程内容
2.1 创建临时节点
create -e /names/temp-dump 111
3 Coding
诸葛