zookeeper介绍及mac环境搭建(5)
- 2020 年 3 月 17 日
- 筆記
zookeeper 基本介绍
zookeeper是Apacahe Hadoop的子项目,是一个树型的目录服务,支持变更推送,适合作为Dubbo服务的注册中心,工业强度高,可用于生产环境,并推荐使用
zookeeper环境搭建(mac)
此地址 下载zookeeper-3.4.10.tar.gz
MacOS:10.13.1 zookeeper-3.4.13
- 下载后通过命令行进入压缩包所在的目录并执行解压命令
tar -zxvf zookeeper-3.4.10.tar.gz // 解压
- 进入conf目录下,修改默认配置文件名称,将zoo_sample.cfg 修改为zoo.cfg
cd zookeeper-3.4.10/conf // 切换目录 mv zoo_sample.cfg zoo.cfg // 修改名称
3.打开文件zoo.cfg
dataDir:临时数据存储位置 clientPort:zookeeper的端口号

- 通过命令切换目录到zookeeper的目录下,启动Server
cd zookeeper-3.4.10/bin // 切换目录 ./zkServer.sh start // 启动服务 ZooKeeper JMX enabled by default Using config: zookeeper-3.4.10/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
- cli连接
zookeeper启动后,重新打开新的命令行窗口切换目录到zookeeper的目录下,启动cli,通过cli连接zookeeper服务器
cd zookeeper-3.4.10/bin //切换到 bin目录 ./zkCli.sh -server 127.0.0.1:2181
- 使用zkCli.cmd测试
ls /:列出zookeeper根下保存的所有节点 create -e/aaa 123:创建一个aaa节点,值为123 get /aaa:获取/aaa节点的值
./zkCli.sh -server 127.0.0.1:2181 [zk: 127.0.0.1:2181(CONNECTED) 0] help //输入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 /////////////////////官方测试命令//////////////////////// [zk: 127.0.0.1:2181(CONNECTED) 2] ls / [zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 3] create /zk_test my_data Created /zk_test [zk: 127.0.0.1:2181(CONNECTED) 4] ls / [zookeeper, zk_test] [zk: 127.0.0.1:2181(CONNECTED) 5] get /zk_test my_data cZxid = 0x2 ctime = Wed Feb 28 15:18:45 CST 2018 mZxid = 0x2 mtime = Wed Feb 28 15:18:45 CST 2018 pZxid = 0x2 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 6] set /zk_test junk cZxid = 0x2 ctime = Wed Feb 28 15:18:45 CST 2018 mZxid = 0x3 mtime = Wed Feb 28 15:20:23 CST 2018 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 7] get /zk_test junk cZxid = 0x2 ctime = Wed Feb 28 15:18:45 CST 2018 mZxid = 0x3 mtime = Wed Feb 28 15:20:23 CST 2018 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 8] delete /zk_test [zk: 127.0.0.1:2181(CONNECTED) 9] ls [zk: 127.0.0.1:2181(CONNECTED) 10] ls / [zookeeper]
- 停止Server
> ./zkServer.sh stop ////停止后,如果CLi没有关闭,将报错