1.下载Zookeeper http://mirrors.shu.edu.cn/apache/zookeeper/
这里我选择Zookeeper 3.4.11版本 ZooKeeper 支持某些特定的四字命令字母与其的交互。它们大多是查询命令,用来获取 ZooKeeper 服务的当前状态及相关信息。用户在可以通过 telnet 或 nc 向 ZooKeeper 提交相应的命令。 ZooKeeper 常用四字命令见下表 1 所示: 表 1 : ZooKeeper 四字命令
2. 配置环境
首先 把下载好的Zookeeper包 解压以后复制 全部内容 到 D:/zookeeper目录 下,然后进入目录D:/zookeeper/conf/ 新建一个名为zoo.cfg的文件
复制以下代码,保存退出。
# The number of milliseconds of each tick 心跳间隔 毫秒每次 tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting anacknowledgement syncLimit=5 # the directory where the snapshot isstored. //镜像数据位置 dataDir=D:\\data\\zookeeper #日志位置 dataLogDir=D:\\logs\\zookeeper # the port at which the clients willconnect 客户端连接的端口 clientPort=2181 注:如果启动有报错提示cfg文件有错误,可以用zoo_sample.cfg内内容替代也是可以的
3. 启动 Zookeeper 服务端 (注 : .sh 和 .cmd 文件 分别用在 Unix 和 Windows 平台)
启动cmd,切换到 D://zookeeper/bin/ 输入 zkServer.cmd
C:\Users\Administrator.PC-20170306CZRV>D: D:\>cd zookeeper\bin D:\zookeeper\bin>zkServer.cmd
4. 新打开一个命令窗口 ,启动客户端
C:\Users\Administrator.PC-20170306CZRV>D: D:\>cd zookeeper\bin D:\zookeeper\bin>zkCli.cmd -server 127.0.0.1:2181
连接成功以后会出现 下面这段消息
[zk: 127.0.0.1:2181(CONNECTING) 0] 2018-04-17 14:43:02,544 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1302] - Session establishment
complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x10000300da50000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null
5. 进行节点操作(增删改查 create delete set get )
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 4] create /zk-user yzr
Created /zk-user
[zk: 127.0.0.1:2181(CONNECTED) 6] ls /
[zk-user, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 7] get /zk-user
yzr
cZxid = 0x2
ctime = Tue Apr 17 14:46:23 CST 2018
mZxid = 0x2
mtime = Tue Apr 17 14:46:23 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 3
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 8] set /zk-user lyf
[zk: 127.0.0.1:2181(CONNECTED) 9] delete /zk-user