ZooKeeper 环境搭建
官网
官网下载
ZooKeeper 需要安装JDK环境
单机部署
Windows
下载压缩包解压
复制zookeeper目录下的conf/zoo_sample.cfg到conf/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=/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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
运行 apache-zookeeper-3.7.0-bin/bin/zkServer.cmd
默认客户端端口 0.0.0.0/0.0.0.0:2181
Linux (CenterOS 7)
下载压缩包
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
解压 可以自己指定路径
tar -zxvf zookeeper-3.7.0.tar.gz
cd apache-zookeeper-3.7.0-bin/
ls
# bin conf docs lib LICENSE.txt NOTICE.txt README.md README_packaging.md
cd conf
#复制配置
cp zoo_sample.cfg zoo.cfg
修改配置zoo.cfg
vim zoo.cfg
dataDir=/root/zookeeper-data
运行服务
./zkServer.sh start
停止服务
./zkServer.sh stop
集群配置
配置参数
参数 | 描述 |
---|---|
tickTime =2000 | 通信心跳数,Zookeeper服务器与客户端心跳时间,单位毫秒 |
initLimit =10 | LF初始通信时限 |
syncLimit =5 | LF同步通信时限 |
dataDir | 数据文件目录+数据持久化路径 |
clientPort =2181 | 客户端连接端口 |
复制三份ZooKeeper 模拟集群
各添加配置
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2887:3887
修改客户端端口分别如下
clientPort=2181
clientPort=2182
clientPort=2183
配置完成分别启动,Window和Linux区别在于操作不同、Windows执行命令为.cmd,Linux 为.sh