下载
wget http://archive.apache.org/dist/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
解压
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
移动到/usr/local
mv apache-zookeeper-3.7.0-bin zookeeper
mv zookeeper /usr/local/
进入 cd /usr/local/zookepper
mkdir logs
mkdir data
创建配置文件
cd conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
# 它是zk中所有涉及到时间长度的基本时间单元,心跳间隔等于tickTime,最小的 session 过期时间为2倍tickTime
tickTime=2000
# 配置 Leader 等待 Follower启动并完成数据同步的时间,以tickTime为单位。例如tickTime=2000,initLimit=2表示4秒
initLimit=10
# 它也表示follower与leader交互时的最大等待时间,比如在与leader同步完毕之后,进入正常请求转发或ping等消息交互时的超时时间
syncLimit=5
# 数据目录,主要目的是存储内存数据库序列化后的快照路径。如果没有配置事务日志(即dataLogDir配置项)的路径,那么ZooKeeper的事务日志也存放在数据目录中
dataDir=/usr/local/zookeeper/data
# 日志文件夹
dataLogDir=/usr/local/zookeeper/logs
# 客户端连接的端口
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
创建systemctl守护进程
vim /lib/systemd/system/zookeeper.service
[Unit]
Description=Zookeeper Service unit Configuration
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/jdk/jdk-11
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start zookeeper
systemctl stop zookeeper
systemctl restart zookeeper