一、下载
官网:http://www.apache.org/dyn/closer.cgi/zookeeper
下载apache-zookeeper-3.5.5-bin.tar.gz
二、安装(单机模式)
$ mv apache-zookeeper-3.5.5-bin.tar.gz ~/Applications
$ tar -zxf apache-zookeeper-3.5.5-bin.tar.gz
$ cd ~/Applications/apache-zookeeper-3.5.5-bin/conf
$ cp zoo_sample.cfg zoo.cfg
$ vim 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=/Users/lyf/Applications/apache-zookeeper-3.5.5-bin/data
dataLogDir=/Users/lyf/Applications/apache-zookeeper-3.5.5-bin/datalog
# 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
参数及含义:
trickTime:心跳时间,zookeeper中独立的工作时间单元,以毫秒为单位,默认情况下最小的会话超时时间是两倍的trickTime
initLimit:zookeeper接受客户端连接时的超时时间(多少个心跳间隔),这里的客户端不是指连接服务器的客户端,而是针对zookeeper集群中连接Leader的Follower服务器。如果超过10个心跳时间(10*2000ms=20s)Leader服务器还未收到客户端返回的信息,则表明这个客户端连接失败
syncLimit:多少个心跳时间内,允许Follower同步数据,若落后太多,则会被弃用
dataDir:用于存放内存数据快照的目录,用于集群的myid文件也会存放此目录下
dataLogDir:用于单独存放事务日志(transaction log)的目录
clientPost:服务的监听端口
maxClientCnxns:最大的客户端连接数量
三、启动zkServer
服务命令
Bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
—config 指定配置文件
start 作为后台程序启动
strat-foreground 作为前端程序启动
stop 停止服务
restart 重启服务
status 查看服务状态
print-cmd 显示出服务启动的相关信息
- 启动服务
$ cd ~/Applications/apache-zookeeper-3.5.5-bin
$ bin/zkServer.sh start
- 启动zkCli
$ bin/zkCli.sh # 默认连接到本地的zookeeper服务器
$ bin/zkCli.sh -server IP:PORT # 连接指定IP的zookeeper服务器上
$ bin/zkCli.sh -timeout 3000 -server IP:PORT # 设置timeout
- 退出zkCli
[zk: localhost:2181(CLOSED) 2] quit
- 停止zkServer
$ bin/zkServer.sh stop
问题:
启动失败
查看日志
提示错误: 找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain
出现该问题的原因可能为:安装包下载错误,二进制文件才可以直接运行
版本3.5.5进行了较大的结构调整
参考:
[1] https://zookeeper.apache.org/doc/current/zookeeperOver.html
[2] https://blog.youkuaiyun.com/r244925932/article/details/81474702