1. 下載
-
或者去這里現(xiàn)在你需要的版本
root@debian:~/soft/bk# wget http://mirrors.hust.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
2. 安裝和配置
限于測試環(huán)境屠尊,只在單機(jī)上部署3個(gè)實(shí)例毅臊,生產(chǎn)環(huán)境需要所有實(shí)例分散在不同的機(jī)器上
-
解壓縮
# 解壓縮 root@debian:~/soft/bk# tar zxvf zookeeper-3.4.12.tar.gz root@debian:~/soft/bk# cd zookeeper-3.4.12/ # 刪除一些不要的文件,最后只留下面這些文件 root@debian:~/soft/bk/zookeeper-3.4.12# ls -l total 1464 drwxr-xr-x 2 psy psy 4096 Mar 27 12:32 bin drwxr-xr-x 2 psy psy 4096 Mar 27 12:32 conf drwxr-xr-x 4 psy psy 4096 Mar 27 12:32 lib -rw-rw-r-- 1 psy psy 1483366 Mar 27 12:32 zookeeper-3.4.12.jar
-
創(chuàng)建配置文件
root@debian:~/soft/bk/zookeeper-3.4.12# cd conf/ root@debian:~/soft/bk/zookeeper-3.4.12/conf# ls configuration.xsl log4j.properties zoo_sample.cfg root@debian:~/soft/bk/zookeeper-3.4.12/conf# cp zoo_sample.cfg zoo.cfg root@debian:~/soft/bk/zookeeper-3.4.12/conf# vim zoo.cfg
修改配置文件zoo.cfg的內(nèi)容
# 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=/data/zookeeper/data/z1 # the port at which the clients will connect clientPort=2281 server.1=localhost:2888:3888 server.2=localhost:2889:3889 server.3=localhost:2890:3890 # 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
-
安裝
root@debian:~/soft/bk# mkdir -p /usr/local/zookeeper_cluster root@debian:~/soft/bk# cp -r zookeeper-3.4.12 /usr/local/zookeeper_cluster/z1 root@debian:~/soft/bk# cp -r zookeeper-3.4.12 /usr/local/zookeeper_cluster/z2 root@debian:~/soft/bk# cp -r zookeeper-3.4.12 /usr/local/zookeeper_cluster/z3
z1, z2, z3 分別是三個(gè)實(shí)例
- 修改z2/conf/zoo.cfg, 修改dataDir和clientPort項(xiàng)
dataDir=/data/zookeeper/data/z2 # the port at which the clients will connect clientPort=2282
- 修改z3/conf/zoo.cfg, 修改dataDir和clientPort項(xiàng)
dataDir=/data/zookeeper/data/z3 # the port at which the clients will connect clientPort=2283
- 修改z2/conf/zoo.cfg, 修改dataDir和clientPort項(xiàng)
-
創(chuàng)建數(shù)據(jù)存儲(chǔ)目錄
root@debian:~/soft/bk/zookeeper-3.4.12# mkdir -p /data/zookeeper/data root@debian:~/soft/bk/zookeeper-3.4.12# cd /data/zookeeper/data/ root@debian:/data/zookeeper/data# mkdir z1 z2 z3
-
創(chuàng)建myid, id與zoo.cfg中server.X的x對應(yīng)
root@debian:/data/zookeeper/data# echo 1 > z1/myid root@debian:/data/zookeeper/data# echo 2 > z2/myid root@debian:/data/zookeeper/data# echo 3 > z3/myid
3. 啟動(dòng)和測試
- 創(chuàng)建一個(gè)啟動(dòng)三個(gè)實(shí)例的sh, start.sh
./z1/bin/zkServer.sh start & ./z2/bin/zkServer.sh start & ./z3/bin/zkServer.sh start &
- 測試
一些操作命令root@debian:/usr/local/zookeeper_cluster/z1/bin# ./zkCli.sh -server 127.0.0.1:2281
[zk: 127.0.0.1:2281(CONNECTED) 2] create /zk_test hello Created /zk_test [zk: 127.0.0.1:2281(CONNECTED) 3] get /zk_test hello cZxid = 0x100000003 ctime = Wed Sep 19 18:04:00 CST 2018 mZxid = 0x100000003 mtime = Wed Sep 19 18:04:00 CST 2018 pZxid = 0x100000003 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 [zk: 127.0.0.1:2281(CONNECTED) 4] set /zk_test fuck cZxid = 0x100000007 ctime = Wed Sep 19 18:09:32 CST 2018 mZxid = 0x100000008 mtime = Wed Sep 19 18:09:40 CST 2018 pZxid = 0x100000007 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: 127.0.0.1:2281(CONNECTED) 5] get /zk_test fuck cZxid = 0x100000007 ctime = Wed Sep 19 18:09:32 CST 2018 mZxid = 0x100000008 mtime = Wed Sep 19 18:09:40 CST 2018 pZxid = 0x100000007 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0 [zk: 127.0.0.1:2281(CONNECTED) 6] delete /zk_test [zk: 127.0.0.1:2281(CONNECTED) 7] ls / [zookeeper] [zk: 127.0.0.1:2281(CONNECTED) 8]