下载 选择自己的版本,我这里下载的是3.4.13

解压

tar zxvf zookeeper-3.4.13

修改配置
找到你解压的目录,进入到conf目录下,在当前目录下复制zoo_sample.cfg,并改名为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
dataDir=/home/yf/soft/work/zookeeper/zookeeper-3.4.13/zookeeperdir/zookeeper-data
dataLogDir=/home/yf/soft/work/zookeeper/zookeeper-3.4.13/zookeeperdir/logs
# the port at which the clients will connect
clientPort=2181
server.1=127.0.0.1:2888:3888
# 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

记得新建这2个目录

dataDir=/home/yf/soft/work/zookeeper/zookeeper-3.4.13/zookeeperdir/zookeeper-data
dataLogDir=/home/yf/soft/work/zookeeper/zookeeper-3.4.13/zookeeperdir/logs

2888端口号是zookeeper服务之间通信的端口,而3888是zookeeper与其他应用程序通信的端口

在到zookeeper-data目录下 新建 myid 文件
切换到zookeeper-data目录下 ,执行 touch myid,填写内容1,就是zoo.cfg文件里server.1的数字对应

自己去配置环境变量,配置到bin目录即可

export ZOOKEEPER_HOME=/home/yf/soft/work/zookeeper/zookeeper-3.4.13
export PATH=$PATH:$ZOOKEEPER_HOME/bin 

启动服务端
此时把目录切换到bin目录下

启动zookeeper

./zkServer.sh start

查看状态

./zkServer.sh status

关闭

./zkServer.sh stop

再次查看状态,此时一系列的打印如下图
这里写图片描述

启动客户端脚本

./zkCli.sh -server 127.0.0.1:2181

这里写图片描述

注意:由于LZ的电脑是linux 系统,不是虚拟机,有可能某些地方有差别,比如解压文件,我这里双击即可

本文参考 https://zookeeper.apache.org/doc/current/zookeeperStarted.html
https://my.oschina.net/phoebus789/blog/730787

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐