1 准备
centos7、zookeeper-3.4.9.tar.gz(下载地址:https://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/)
2 安装
2.1 进入到自己存放zookeeper安装包的目录
2.2 当前目录执行命令:tar -zxvf zookeeper-3.4.9.tar.gz
2.3 进入根目录,创建myzookeeper文件夹
2.4 进入/opt目录,将之前解压的zookeeper-3.4.9复制到/myzookeeper下
cp -r zookeeper-3.4.9 /myzookeeper/
2.5 进入/myzookeeper/zookeeper-3.4.9/conf,将zoo_sample.cfg复制一份命名为zoo.cfg。
cp zoo_sample.cfg zoo.cfg
2.6 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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=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
tickTime
通信心跳数,zookeeper服务器心跳时间,单位为毫秒。
zookeeper使用的基本时间,服务器之间或者客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间会发送一个心跳,单位时间为毫秒。
它用于心跳机制,并且设置最小的心跳session超时时间为两倍心跳时间(即session的最小心跳时间为2*tickTime)。
initLimit
表示LF初始通信时限,集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。用它来限定集群中的zookeeper服务器连接到leader的时限。
syncLimit
表示LF同步通信时限。集群中Leader与Follower之间的最大响应时间单位,假如响应时间超过syncLimit*tickTime,Leader认为Follower死掉,从服务器列表中删除Follower。
在运行过程中,Lead负责与ZK集群中所有机器进行通讯,假如通过一些心跳检测机制,来检测机器的存货状态。如果L发出心跳包在syncLimit之后,还没有从F那收到响应,那么就认为这个F已经不在线了。
dataDir
数据目录,生产中是需要更改这个目录的。
clientPort
指定的端口。
2.7 启动
进入bin目录,启动或关闭zookeeper(需要JDK支持,所以需要先配置好java环境变量)
启动:./zkServer.sh start
关闭:./zkServer.sh stop
启动zk后,再启动客户端,执行命令:./zkCli.sh
客户端启动后,执行命令:echo ruok | nc 127.0.0.1 2181,如果返回imok,那么就成功了。
执行命令:echo stat | nc 127.0.0.1 2181,可以查看一些信息