Zookeeper的安裝和配置十分簡單, 既能夠配置成單機模式, 也能夠配置成集羣模式. 下面介紹單機版的安裝。bash
tar -zvxf zookeeper-3.4.9.tar.gz
mkdir data mkdir logs
cp zoo_sample.cfg 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 an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/tmp/zookeeper # the port at which the clients will connect clientPort=2181 dataDir=/usr/local/zookeeper/zookeeper-3.4.9/data dataLogDir=/usr/local/zookeeper/zookeeper-3.4.9/logs
配置說明:網絡
- tickTime
時長單位爲毫秒,爲zk使用的基本時間度量單位。例如,1 * tickTime是客戶端與zk服務端的心跳時間,2 * tickTime是客戶端會話的超時時間。 tickTime的默認值爲2000毫秒,更低的tickTime值能夠更快地發現超時問題,但也會致使更高的網絡流量(心跳消息)和更高的CPU使用率(會話的跟蹤處理)。工具
- clientPort
zk服務進程監聽的TCP端口,默認狀況下,服務端會監聽2181端口。code
- dataDir
無默認配置,必須配置,用於配置存儲快照文件的目錄。進程
- dataLogDir
log目錄, 能夠是任意目錄. 若是沒有設置該參數, 將使用和dataDir相同的設置。get
- clientPort
監聽client鏈接的端口號。it
bin/zkServer.sh start
bin/zkServer.sh status
bin/zkServer.sh stop
chkconfig --add zookeeper
su - root -c '/usr/local/zookeeper/zookeeper-3.4.9/bin/zkServer.sh start'