一、下載
官網(wǎng)下載鏈接:https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
二、安裝
這里我是在本地(mac)安裝滴,也可以在服務(wù)器安裝,隨你啦。
在本地解壓至/Users/用戶名/app:
tar -zxvf zookeeper-3.4.6.tar.gz -C /Users/huluwa/app
將解壓后的文件夾改名:
mv zookeeper-3.4.6/ zookeeper
三、配置(要運行zk就需要此配置)
在安裝路徑:/Users/huluwa/app/zookeeper/conf中 新建 配置文件zoo.cfg

cp zoo_sample.cfg zoo.cfg
conf中的zoo_sample.cfg是默認(rèn)的配置文件(以cfg結(jié)尾),如果用戶沒有新建cfg配置文件,就使用默認(rèn)的。
now,先新建一個文件夾用于配置中的dataDir路徑配置。
vim ~/data #路徑為 /Users/huluwa/data
接著配置zoo.cfg(主要是配置dataDir):
# 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 an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# dataDir=/root/data/zookeeper
dataDir=/Users/huluwa/data #其實主要是配置這個參數(shù)啦啦啦
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
四、配置環(huán)境變量
這步可配也可以不配置。配置了就能在全局執(zhí)行zk的命令了,不然只能進入zk 的安裝路徑下執(zhí)行一些命令。
五、啟動服務(wù)
進入zk安裝路徑
cd ~/app/zookeeper/
cd bin/
ls

zkCli.sh 客戶端執(zhí)行文件, zkServer.sh 服務(wù)端執(zhí)行文件
ok,let's 啟動客戶端服務(wù):
./zkServer.sh start
omg! 出現(xiàn)了權(quán)限錯誤:

那我們給這個文件夾賦全部的權(quán)限吧!
chmod -R 777 /Users/huluwa/data/zookeeper #777是全部的權(quán)限
ok,再一次啟動服務(wù)端服務(wù):
./zkServer.sh start

六、查看zookeeper運行及狀態(tài)
安裝后,可以看到zookeeper提供了zkCli等工具。
同樣,在bin目錄下,執(zhí)行:
./zkCli.sh
