一、Zookeeper下载
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
二、Zookeeper解压
tar -zxvf /usr/program/zookeeper/zookeeper-3.4.9.tar.gz
三、进入conf目录
cd /usr/program/zookeeper/zookeeper-3.4.9/conf
拷贝zoo_sample.cfg为zoo.cfg
cp zoo_sample.cfg zoo.cfg
编辑zoo.cfg
vim zoo.cfg
配置成下面的样子
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/usr/program/zookeeper/zookeeper-3.4.9/data# the directory stored data logdataLogDir=/usr/program/zookeeper/zookeeper-3.4.9/log# the port at which the clients will connectclientPort=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# service configserver.1=192.168.239.131:2888:3888
四、设置环境变量
export ZOOKEEPER_INSTALL=/usr/program/zookeeper/zookeeper-3.4.9
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
export PATH=$PATH:$ZOOKEEPER_INSTALL/conf
进入/etc目录下,用source profile命令使它生效
五、启动
./zkServer.sh start
六、测试
./zkCli.sh -server 192.168.239.131:2181
---->>>集群配置<<<---
将zoo.cfg的service配置如下
server.1=192.168.239.131:2888:3888server.2=192.168.239.130:2888:3888server.3=192.168.239.132:2888:3888
在zoo.cfg配置dataDir对应的目录下创建myid文件,并在对应的机器上输入1、2、3(如:server.1这台机输入1,server.2这台机输入2,server.3这台机输入3)
使用打印日志的方式启动
./zkServer.sh start-foreground(使用这种方式启动,如果按Ctrl+Z退出日志查看,服务就会挂掉,还不清楚为什么!)
使用下面命令查看启动信息
./zkServer.sh status
ZooKeeper JMX enabled by defaultUsing config: /usr/program/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfgMode: leader