1.下载Zookeeper
Zookeeper下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
上面地址是apache zookeeper网站上的下载地址,进入后选择你需要的版本,点击下载就可以了,我这里选择3.4.10。
2.解压zookeeper包
将下载的zookeeper-3.4.10.tar.gz利用压缩软件解压到本地磁盘,我解压路径是E:\zookeeper目录下。
3.修改配置
进入zookeeper解压目录E:\zookeeper\zookeeper-3.4.10,修改conf下的zoo_sample.cfg配置文件,先将文件名称修改为zoo.cfg,或者新建一个zoo.cfg的文件,
如果是修改文件的话,需要修改以下配置,如果是新建文件的话,需要在文件中增加如下配置(其中tickTime,clientPort,dataDir,dataLogDir):
#
# 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=E:\zookeeper\data
dataLogDir=E:\zookeeper\logs
# 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中的时间单元,以毫秒为单位,默认超时时间设置2*tickTime;
initLimit:leader允许follower在启动后多少个心跳时间内,允许其同步初始化数据,如果ZooKeeper管理的数据较大,则应相应增大这个值;
syncLimit:zookeeper的leader通过心跳检测机制来检测节点的存活状态,如果leader发送请求,在syncLimit次数后还没有收到返回消息,就会认为该节点不存在了;
dataDir:数据的快照存储目录,默认情况下,如果没有配置dataLogDir目录的话,数据事物日志文件也会存在这个目录下,如果是集群的话,myid文件也会存在这个目录下;
dataLogDir:事物日志存储的目录,建议配置这个参数并和dataDir路径分开,事务日志的写会影响ZK的性能;
clientPort:客户端连接server的端口,即对外服务的端口;
maxClientCnxns:单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是60,如果设置为0,那么表明不作任何限制;
autopurge.snapRetainCount:快照文件保留的数目;
autopurge.purgeInterval:3.4.0版本之后,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,0表示不开启自动清理功能。
4.启动zookeeper服务
进入到E:\zookeeper\zookeeper-3.4.10\bin目录下,启动zkServer.cmd,这个脚本中会启动一个java进程。
E:\zookeeper\zookeeper-3.4.10\bin> zkServer.cmd
另起一个命令窗口,启动客户端连接试一下,
E:\zookeeper\zookeeper-3.4.10\bin> zkCli.cmd -server 127.0.0.1:2181,能看到连接的信息。
这时zookeeper单机节点的已经就安装完了。