ZooKeeper 环境
大约 2 分钟
ZooKeeper 环境
1 Downloads
kafka 环境依赖 zookeeper 环境,本文简单记录一下 zookeeper 环境搭建。
apache-zookeeper-3.7.0-bin.tar.gz
: https://zookeeper.apache.org/releases.html
1.1 文件校验
https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz.sha512
$ Get-FileHash apache-zookeeper-3.7.0-bin.tar.gz -Algorithm SHA512 | Format-List
Algorithm : SHA512
Hash : 64E2701C019ED46F45F4D53B2C5EAEAF7CF48C342BBAFA032A0819D527FC77CAEBFADA6BDAD34E5171E6D838F40B16C95B62CE378B53DFC827AF2D60CEC0B17C
Path : D:\下载2\linux-downloads\apache-zookeeper-3.7.0-bin.tar.gz
2 配置文件
./conf/zoo.cfg
# The number of milliseconds of each tick 服务器心跳时间,单位为 ms
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take 投票选举新 leader 的初始化时间
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement leader 与 fellower 心跳检测最大容忍时间,响应超过 syncLimit * tickTime,leader 认为 fellower “死掉”,剔除 fellower
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
3 standalone mode(单机模式)
环境依赖 JAVA_HOME
。
# 解压
tar zxvf apache-zookeeper-3.7.0-bin.tar.gz
cd apache-zookeeper-3.7.0-bin
# 复制配置文件
$ cp conf/zoo_sample.cfg conf/zoo.cfg
# 启动服务
$ ./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
# 停止服务
$ ./bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
# 查看状态
$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
4 replicated mode(集群模式)
官方文档: https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_InstallingSingleMode
/etc/hosts
192.168.3.19 localhost.ubuntu0.com
192.168.3.20 localhost.ubuntu1.com
192.168.3.21 localhost.ubuntu2.com
./conf/zoo.cfg
server.0=localhost.ubuntu0.com:2888:3888
server.1=localhost.ubuntu1.com:2888:3888
server.2=localhost.ubuntu2.com:2888:3888
/tmp/zookeeper/myid
# localhost.ubuntu0.com
0
# localhost.ubuntu1.com
1
# localhost.ubuntu2.com
2
# localhost.ubuntu0.com
$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
# localhost.ubuntu1.com
$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
# localhost.ubuntu2.com
$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/admin0/Downloads/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
运行截图:
(全文完)