zookeeper在linux下自启动

时间:2023-03-09 16:34:41
zookeeper在linux下自启动

Linux下设置zookeeper开机自启动 

一、以root用户登录系统:

二、进入init.d文件夹

cd /etc/init.d/

三、创建并打开zookeeper文件

vi zookeeper

四、zookeeper文件如下:  

#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/usr/java/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
case $1 in
         start) su root /usr/zookeeper/bin/zkServer.sh start;;
         stop) su root /usr/zookeeper/bin/zkServer.sh stop;;
         status) su root /usr/zookeeper/bin/zkServer.sh status;;
         restart) su root /usr/zookeeper/bin/zkServer.shrestart;;
         *)  echo "requirestart|stop|status|restart"  ;;
esac

五、保存退出

:wq

六、加权限,把 zookeeper修改为可运行的文件,命令参考如下:

chmod 755 apache

 chmod a+x tomcat 

七、使用chkconfig命令把 zookeeper命令加入到系统启动队列中:

chkconfig --add zookeeper

八、查看zookeeper的状态:

chkconfig --list zookeeper

九、测试

service zookeeper start

service zookeeper stop

service zookeeper restart

service zookeeper status