1. 安装 jdk,zookeeper 就不说啦, 自己搜索下.
2. 开机自启动和注册为服务.
(1) 开机自启动: 编辑 / etc/rc.d/rc.local 文件, 添加 zkServer.sh 路径.
- vi /etc/rc.d/rc.local
- #!/bin/sh
- # This script will be executed *after* all the other init scripts.
- # You can put your own initialization stuff in here if you don't
- # want to do the full Sys V style init stuff.
- touch /var/lock/subsys/local
export JAVA_HOME=/usr/java/jdk1.8.0_221 --jdk 的路径, 自己安装的目录
/home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start --zookeeper 的 zkServer.sh 的路径
(2) 注册为服务: 到 / etc/rc.d/init.d 目录下添加, zookeeper 脚本
- cd /etc/rc.d/init.d
- touch zookeeper
ls -al -- 查看到没有执行权限, 修改权限
chmod +x zookeeper
vi zookeeper -- 打开 zookeeper 编辑脚本, 下面为要 编辑的内容
- #! /bin/bash
- #chkconfig: 2345 20 90 -- 系统启动级别为 2 3 4 5 启动优先级 20 关闭优先权 90. 必须, 否则执行 chkconfig 命令是会报错
- #description:zookeeper
- #processname:zookeeper
- export JAVA_HOME=/usr/java/jdk1.8.0_221
- case $1 in
- start) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start;;
- stop) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh stop;;
- status) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh status;;
- restart) su /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh restart;;
- *) echo "require start|stop|status|restart" ;;
- esac
添加好后保存. 测试:
service zookeeper start
启动成功后则添加服务成功了.
(3) 将服务添加为开机启动.
chkconfig --add zookeeper --zookeeper 为刚才注册的服务
chkconfig --list -- 查看刚才添加的 zookeeper 是否成功. 有显示为成功.
来源: http://www.bubuko.com/infodetail-3147762.html