安装
Zookeeper
wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz
tar zxvf zookeeper-3.4.8.tar.gz -C /usr/local
cd /usr/local && mv zookeeper-3.4.8 zookeeper
cd zookeeper
cp conf/zoo_sample.cfg conf/zoo.cfg
libZookeeper
cd /usr/local/zookeeper-3.4.8/src/c
./configure -prefix=/usr/local/libzookeeper/
make && make install
php扩展Zookeeper
cd /usr/local/src/
wget http:pecl.php.net/get/zookeeper-0.3.2.tgz
tar -zxvf zookeeper-0.3.2.tgz
cd zookeeper-0.3.2
phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-libzookeeper-dir=/usr/local/zookeeper/
make && make install
启动
单机启动
新建事务日志与快照目录
mkdir /usr/local/zookeeper/logs
mkdir /usr/local/zookeeper/data
编辑配置文件
vim /usr/local/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper/logs
dataDir=/usr/local/zookeeper/data
clientPort=2181
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
启动
/usr/local/zookeeper/bin/zkServer.sh start
伪分布方式启动
准备:
mkdir /usr/local/zookeeper/logs1
mkdir /usr/local/zookeeper/data1
mkdir /usr/local/zookeeper/logs2
mkdir /usr/local/zookeeper/data2
mkdir /usr/local/zookeeper/logs3
mkdir /usr/local/zookeeper/data3
echo 1 > /usr/local/zookeeper/data1/myid
echo 2 > /usr/local/zookeeper/data2/myid
echo 3 > /usr/local/zookeeper/data3/myid
vim /usr/local/zookeeper/conf/zoo1.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper/logs1
dataDir=/usr/local/zookeeper/data1
clientPort=2181
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.28.180:2888:3888
server.2= 192.168.28.180:4888:5888
server.3= 192.168.28.180:6888:7888
vim /usr/local/zookeeper/conf/zoo2.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper/logs2
dataDir=/usr/local/zookeeper/data2
clientPort=2182
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1=192.168.28.180:2888:3888
server.2= 192.168.28.180:4888:5888
server.3= 192.168.28.180:6888:7888
vim /usr/local/zookeeper/conf/zoo3.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper/logs3
dataDir=/usr/local/zookeeper/data3
clientPort=2183
autopurge.
snapRetainCount=500
autopurge.purgeInterval=24
server.1=192.168.28.180:2888:3888
server.2= 192.168.28.180:4888:5888
server.3= 192.168.28.180:6888:7888
启动
./bin/zkServer.sh start ./conf/zoo1.cfg
./bin/zkServer.sh start ./conf/zoo2.cfg
./bin/zkServer.sh start ./conf/zoo3.cfg
集群方式启动
每台机器按照下面执行操作
唯一不同的是/usr/local/zookeeper/data/myid里面的值要与配置里面的server.后面的num对应
新建事务日志与快照目录
mkdir /usr/local/zookeeper/logs
mkdir /usr/local/zookeeper/data
编辑配置文件
vim /usr/local/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/usr/local/zookeeper/logs
dataDir=/usr/local/zookeeper/data
clientPort=2181
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.28.181:2888:3888
server.2= 192.168.28.182:2888:3888
server.3= 192.168.28.183:2888:3888
依次启动
/usr/local/zookeeper/bin/zkServer.sh start