下载可用的zookeeper程序,上传至linux主机,解压缩
% tar –zxvf zookeeper-3.4.7.tar.gz
设置环境变量,将目录指向新解压的路径
export ZOOKEEPER_HOME=~/usr/software/zookeeper-3.4.7
export PATH=$PATH:$ZOOKEEPER_HOME/bin
然后修改配置文件 ZOOKEEPER_HOME/conf/zoo.cfg,新解压的目录没有这个文件,将zoo_sample.cfg这个文件 改名即可
cp zoo_sample.cfg zoo.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 isstored.
# do not use /tmp for storage, /tmp here isjust
# example sakes.
dataDir=/usr/software/zookeeper-3.4.7/tmp
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle moreclients
#maxClientCnxns=60
#
# Be sure to read the maintenance section ofthe
# administrator guide before turning onautopurge.
#
#http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain indataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purgefeature
#autopurge.purgeInterval=1
server.1=192.168.56.129:2888:3888
server.2=192.168.56.130:2888:3888
server.3=192.168.56.131:2888:3888
以集群为3个服务器为例,如上server.1 server.2 server.3指定了3个服务器地址
Ticktime属性指定了基本时间单元(毫秒为单位)
Datadir指定了存储持久数据的本地文件系统的位置
Clientport指定用于监听客户端链接的端口,通常使用2181
在tmp目录下,创建服务器的id文件,文件名为myid,打开文件,为对应的服务器指定id,这个id要和zoo.cfg的文件中指定的一致。
其余两个服务器,可以将zookeeper目录直接拷贝过去,然后修改myid的值即可
然后依次在每台服务器执行如下命令:
./zkServer.sh start
ZooKeeper JMX enabled by default
Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
然后使用如下命令查看状态
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg
Mode: follower
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config:/usr/software/zookeeper-3.4.7/bin/../conf/zoo.cfg
Mode: leader
OK,环境搭建完成!