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沒有關閉,將報錯