Zookeeper : 单机版,Windows安装和使用

Zookeeper 单机安装非常简单,

只要获取到 Zookeeper 的压缩包并解压到某个目录如:D:\Java\zookeeper\zookeeper-3.4.12\下,

Zookeeper 的启动脚本在 bin 目录下,Windows 下的启动脚本是 zkServer.cmd

Zookeeper 下载

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

  • Zookeeper 安装首先需要安装JdK,从Oracle的Java网站下载,安装很简单,就不再详述。

JdK下载 :https://blog.csdn.net/fly910905/article/details/85316717

  •  下载后,得到的是一个zookeeper-3.4.12.tar.gz,直接解压即可

Zookeeper 配置

在你执行启动脚本之前,还有几个基本的配置项需要配置一下,Zookeeper 的配置文件在 conf 目录下,这个目录下有 zoo_sample.cfg 和 log4j.properties

你需要做的就是将 zoo_sample.cfg 改名为 zoo.cfg

因为 Zookeeper 在启动时会找这个文件作为默认配置文件。

下面详细介绍一下,这个配置文件中各个配置项的意义。

在windows下配置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=D:\\Java\\zookeeper\\zookeeper-3.4.12\\data
dataLogDir=D:\\Java\\zookeeper\\zookeeper-3.4.12\\log

# 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

zoo.cfg参数解释

  • tickTime:这个时间是作为 Zookeeper 服务器之间客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。通过心跳不仅能够用来监听机器的工作状态,还可以通过心跳来控制Flower跟Leader的通信时间,默认情况下FL的会话时常是心跳间隔的两倍。
  • initLimit:集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
  • syncLimit:集群中flower服务器(F)跟leader(L)服务器之间的发送请求和获取确认最多能容忍的心跳数。   
  • dataDir: Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
  • dataLogDir: Zookeeper 保存日志文件的目录
  • clientPort:客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求,默认是2181。
  • maxClientCnxns:单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是60,如果设置为0,那么表明不作任何限制。请注意这个限制的使用范围,仅仅是单台客户端机器与单台ZK服务器之间的连接数限制,不是针对指定客户端IP,也不是ZK集群的连接数限制,也不是单台ZK对所有客户端的连接数限制。
  • autopurge.purgeInterval:Zookeeper 3.4.0及之后版本,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,需要配置一个1或更大的整数,默认是0,表示不开启自动清理功能。
  • autopurge.snapRetainCount:Zookeeper 3.4.0及之后版本,这个参数和上面的参数搭配使用,这个参数指定了需要保留的文件数目。默认是保留3个。

Zookeeper启动

进入bin 目录下,Windows 下的启动脚本是 zkServer.cmd

启动后要检查 Zookeeper 是否已经在服务,可以通过 netstat – ano 命令查看是否有你配置的 clientPort 端口号在监听服务。

  • 启动中,Zookeeper会主动加载JDK的安装路径

  • 启动中,Zookeeper会加载zoo.cfg的配置信息

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琦彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值