windows环境下安装zookeeper教程详解
第一步(下载安装包)
快速下载
链接:https://pan.baidu.com/s/1x8SNLtI4wUCHrPTOwawQjQ
提取码:r2kq
先准备安装包,这里我推荐在Apache官网下载(地址:https://zookeeper.apache.org/releases.html)。因为这篇文章是为后续dubbo+zk+mybatis+springBoot的教程做铺垫,故选用windows版本做讲解方便各位读者快速上手,后面我会写linux环境下的安装配置及使用。关联dubbo请看https://blog.csdn.net/qq_33316784/article/details/88601513这篇文章。
进入下载入口:
选择任意下载地址:
第二步(开始安装)
解压到常用的安装目录
将conf目录下的zoo_sample.cfg文件,复制一份,重命名为zoo.cfg
修改zoo.cfg配置文件,将dataDir=/tmp/zookeeper修改成zookeeper安装目录所在的data文件夹(需要在安装目录下面新建一个空的data文件夹和log文件夹),再添加一条添加数据日志的配置,
# 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. # 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 ## Metrics Providers # # https://prometheus.io Metrics Exporter #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider #metricsProvider.httpPort=7000 #metricsProvider.exportJvmInfo=true # 端口 admin.serverPort=8082 # 缓存数据路径 dataDir=E:\\1_Tools\\apache-zookeeper-3.6.3-bin\\data # 日志路径 dataLogDir=E:\\1_Tools\\apache-zookeeper-3.6.3-bin\\log
参数说明:
tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒
syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒
dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
第三步(启动程序)
进入bin目录:
zkServer.cmd
验证是否安装成功
zkCli.cmd
出现如图欢迎字样则安装成功!
其他:
启动命令:zkServer.cmd 启动后jps可以看到QuorumPeerMain的进程 jps -l -v 停止命令:cmd zkServer.sh stop // window 版 停止命令:sh zkServer.sh stop // linux 版