设置zookeeper开机自启动

时间:2021-09-04 15:38:43

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

cd /etc/init.d

vi zookeeper

#!/bin/bash    
#
chkconfig:2345 20 90
#
description:zookeeper
#
processname:zookeeper
export JAVA_HOME=/usr/local/programs/jdk1.8
case
$1 in
start) su root
/usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh start;;
stop) su root
/usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh stop;;
status) su root
/usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh status;;
restart) su root
/usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac

 

2.给脚本添加执行权限
chmod +x zookeeper

[root@TestServer-DFJR bin]# cd /etc/init.d
[root@TestServer-DFJR init.d]# chmod +x zookeeper

 

3.使用service zookeeper start/stop命令来尝试启动关闭zookeeper,使用service zookeeper status查看zookeeper状态。
或者直接 zookeeper start/stop/status

 

4.添加到开机启动

[root@TestServer-DFJR init.d]# chkconfig --add zookeeper

 

5.查看开机自启的服务中是否已经有我们的zookeeper

[root@TestServer-DFJR init.d]# chkconfig --list zookeeper
zookeeper 0:off 1:off 2:on 3:on 4:on 5:on 6:off