安装目录: /usr/local/zookeeper(随意指定)
## 集群环境
# /etc/hosts 增加
192.168.1.68 zk.node1
192.168.1.69 zk.node2
192.168.1.70 zk.node3
## 下载安装
http://zookeeper.apache.org/
解压安装包,并放到/usr/local/zookeeper下
# 配置
进入 /usr/local/zookeeper
将 conf/zoo_sample.cfg 重命名为zoo.cfg
# conf/zoo.cfg参数 http://damacheng009.iteye.com/blog/2086461
clientPort=2181 # the port at which the clients will connect
若是单机多instance,则每个zookeeper instance的端口必须不同,不能与下面server.*中端口冲突tickTime=2000 # The number of milliseconds of each tick
基本事件单元,以毫秒为单位。它用来控制心跳和超时,默认情况下最小的会话超时时间为两倍的 tickTimeminSessionTimeout 和 maxSessionTimeout 最小的会话超时时间以及最大的会话超时时间。
最小的会话超时时间默认情况下为 2 倍的 tickTme 时间,最大的会话超时时间默认情况下为 20 倍的会话超时时间dataDir=/opt/zk/data # the directory where the snapshot is stored.
一般情况下,不能将此值设置的比 tickTime 的值还小
存储内存中数据库快照的位置。应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能dataLogDir=/opt/zk/datalog # 日志目录,尽量与dataDir在不同磁盘,防止IO竞争
如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。
initLimit=10 # The number of ticks that the initial synchronization phase can take
客户端定义:不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器
这个配置项是用来配置 Zookeeper 接受客户端"初始化连接"时最长能忍受多少个心跳时间间隔数。
Zookeeper 服务器超过 N 个心跳的时间( tickTime)还没有收到客户端的返回信息,表明这个客户端连接失败syncLimit=5 # The number of ticks that can pass between sending a request and getting an acknowledgement
表示 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过N个 tickTime
如果 follower 在设置的时间内不能与 leader 进行通信,那么此 follower 将被丢弃。peerType=observer
只在observer的node使用的zoo.cfg中配置# 集群相关
server.1=zk.node1:2701:2801
server.2=zk.node2:2701:2801
server.3=zk.node3:2701:2801
server.A=B:C:D[:observer]
A 是一个数字,表示这个是第几号服务器。必须与datadir/myid(zookeeper启动时读取)中的相同
B 是这个服务器的 ip 地址
C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口
D 表示的是集群中的 Leader 服务器挂了,需要此端口来重新进行选举,选出一个新的Leader
如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例的C:D不能相同
observer 表示此server是只读镜像,所有node的zoo.cfg中observer的server后都必须增加:observer
###
将zoo.cfg复制到每个node上