第 2 章 Zookeeper 本地安装
2.1 本地模式安装
1)安装前准备
-
安装 JDK
-
解压改名
bash
# 解压到指定目录
$ tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module
# 修改名称
$ mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
2)配置修改
(1)将/opt/module/zookeeper-3.5.7/conf 这个路径下的 zoo_sample.cfg 修改为 zoo.cfg;
bash
$ mv zoo_sample.cfg zoo.cfg
(2)打开 zoo.cfg 文件,修改 dataDir 路径:
bash
$ vim zoo.cfg
修改如下内容:
bash
dataDir=/opt/module/zookeeper-3.5.7/zkData
(3)在/opt/module/zookeeper-3.5.7/这个目录上创建 zkData 文件夹
bash
$ mkdir zkData
3)操作 Zookeeper
(1)启动 Zookeeper
bash
$ bin/zkServer.sh start
(2)查看进程是否启动
bash
$ jps 4020 Jps
4001 QuorumPeerMain
(3)查看状态
bash
$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Mode: standalone
(4)启动客户端
bash
$ bin/zkCli.sh
(5)退出客户端
bash
[zk: localhost:2181(CONNECTED) 0] quit
(6)停止 Zookeeper
bash
$ bin/zkServer.sh stop
2.2 配置参数解读
zoo_sample.cfg
bash
# 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
Zookeeper中的配置文件zoo.cfg中参数含义解读如下:
1)tickTime = 2000: 通信心跳时间,Zookeeper服务器与客户端心跳时间,单位毫秒
2)initLimit = 10: LF初始通信时限,Leader和Follower初始连接时能容忍的最多心跳数(tickTime的数量)
3)syncLimit = 5: LF同步通信时限,Leader和Follower之间通信时间如果超过syncLimit * tickTime,Leader认为Follwer死 掉,从服务器列表中删除Follwer。
4)dataDir: 保存Zookeeper中的数据,注意:默认的tmp目录,容易被Linux系统定期删除,所以一般不用默认的tmp目录。
5)clientPort = 2181: 客户端连接端口,通常不做修改。
2268

被折叠的 条评论
为什么被折叠?



