Zookeeper的目的是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。Zookeeper有两种运行模式,单机模式(Standalone)和集群模式(Distributed),但是Zookeeper的长处在于可以搭建分布式的Zookeeper集群(一个Leader,多个Follower),从而可以保证集群的高可用性、高稳定性、高可靠性。
下面说明一下Zookeeper两种模式的配置:
在配置Zookeeper之前,下载Zookeeper的安装包:http://zookeeper.apache.org/releases.html#download,我使用的是zookeeper-3.3.6版本的。
Zookeeper的单机模式(standalone)
下载安装包之后,使用Winscp放到Linux的环境中,然后解压安装包:
tar zxvf zookeeper-3.3.6.tar.gz
解压后开始配置Zookeeper,进入到配置文件的目录:
cd zookeeper-3.3.6/conf/
将目录下面的 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.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
上面各个配置参数的含义:
tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。clientPortÿ