- Zookeeper官网下载地址
https://archive.apache.org/dist/zookeeper/
基础安装
- 解压安装包到指定目录
tar -zxvf /home/tools/zookeeper-3.6.1.tar.gz -C /home/software/
- 配置ZooKeeper
- 基于默认配置文件./conf/zoo_sample.cfg复制出一份作为自有的配置:
cp /home/software/zookeeper-3.6.1/conf/zoo_sample.cfg /home/config/zookeeper/zoo.cfg
特别说明:
配置文件读取使用到了正则匹配,
其只支持Linux换行符\n(LF), 不支持Windows下的回车换行符\r\n(CRLF)
否则会出现相关参数读取异常,特别是myid的读取
本人配置文件因换行符问题,运行状态出现了如下故障代码:
[root@localhost zookeeper-3.6.1]# ./bin/zkServer.sh status /home/config/zookeeper/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /home/config/zookeeper/zoo.cfg
myid: No such file or directory
clientPort not found and myid could not be determined. Terminating.
可自行编辑 ./bin/zkServer.sh
搜索myid 附近的读取配置文件代码,使用echo命令来打印读取数据可知故障原因
- 编辑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=/home/data/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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
- tickTime 单位为微秒,用于session注册和客户端和ZooKeeper服务的心跳周期。session超时时长最小为 tickTime的两倍
- dataDir ZooKeeper的状态存储位置,看名字就知道书数据目录。在你的系统中检查这个目录是否存在,如果不存在手动创建,并且给予可写权限。
- clientPort 客户端连接的端口。不同的服务器可以设置不同的监听端口,默认是2181
- 启动ZooKeeper
# zkServer.sh 执行后面带不同配置文件,一台服务器可以运行多个zookeeper服务实例.
./bin/zkServer.sh start /home/config/zookeeper/zoo.cfg
-
查看ZooKeeper是否运行
- 方式1:
./bin/zkServer.sh status /home/config/zookeeper/zoo.cfg
- 方式2:
ps –ef | grep zookeeper
-
常用的zkServer.sh参数
./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
ZooKeeper集群配置
- 设置zookeeper集群各节点ID: 新建myid文件放到(dataDir=/home/data/zookeeper)
cd /home/data/zookeeper
echo 11 > myid
- 配置文件zoo.cfg追加如下配置(server.{myid})
server.11=10.0.1.11:2888:3888
server.12=10.0.1.12:2888:3888
server.13=10.0.1.13:2888:3888
- 重启ZooKeeper
./bin/zkServer.sh restart /home/config/zookeeper/zoo.cfg
- 查看ZooKeeper节点运行状态
./bin/zkServer.sh status /home/config/zookeeper/zoo.cfg
执行结果
[root@localhost zookeeper-3.6.1]# ./bin/zkServer.sh status /home/config/zookeeper/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /home/config/zookeeper/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
网友评论