下载

个人推荐 3.4.14 版,因为较新的版本与 JDK1.8 不兼容。你可以跟随下方截图找到我所说的旧版本,当然,也可以选择其它心仪版本。

https://zookeeper.apache.org/doc/r3.4.14/zookeeperStarted.html

20220607131539.png

https://zookeeper.apache.org/releases.html

20220607131742.png

https://archive.apache.org/dist/zookeeper/

20220607131839.png

https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/

20220607131942.png

安装

解压

tar -zxvf zookeeper-3.4.14.tar.gz 

在安装目录中创建数据目录

mkdir data

修改配置文件

进入安装目录,进入conf目录

cp zoo_sample.cfg zoo.cfg

20220607134726.png

修改启动文件中的日志目录

进入bin目录 /home/zookeeper-3.4.14/bin 找到zkServer.sh在里面加上这个参数配置指定日志目录地址

20220607140115.png

启动服务

需要有Java环境

启动:/home/zookeeper-3.4.14/bin/zkServer.sh start

查看状态:/home/zookeeper-3.4.14/bin/zkServer.sh status

链接测试

使用工具PrettyZoo连接测试

20220607140519.png

开机启动

原文: https://blog.csdn.net/u012453843/article/details/70162796/

直接修改/etc/rc.d/rc.local 文件

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
# yum安装的java的路径
export JAVA_HOME="/usr/lib/jvm/jre-1.8.0"
/home/zookeeper-3.4.14/bin/zkServer.sh start

把 zookeeper 做成服务

1、进入到/etc/rc.d/init.d 目录下,新建一个 zookeeper 脚本

[root@zookeeper ~]# cd /etc/rc.d/init.d/
[root@zookeeper init.d]# pwd
/etc/rc.d/init.d
[root@zookeeper init.d]# touch zookeeper

2、给脚本添加执行权限

[root@zookeeper init.d]# chmod +x zookeeper

3、使用命令 vim zookeeper 进行编辑,同上面注意事项一样要添加export JAVA_HOME="/usr/lib/jvm/jre-1.8.0"这一行,否则无法正常启动。

[root@zookeeper init.d]# vim zookeeper
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0
case $1 in
start) su root /home/zookeeper-3.4.14/bin/zkServer.sh start;;
stop) su root /home/zookeeper-3.4.14/bin/zkServer.sh stop;;
status) su root /home/zookeeper-3.4.14/bin/zkServer.sh status;;
restart) su root /home/zookeeper-3.4.14/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac