zookeeper 设置开机启动在linux系统下

在/etc/rc.d/init.d/下新建zookeeper使用命令 touch zookeeper

将下面内容复制到刚刚新建的文件中

#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/usr/java/jdk1.8.0_161 #换成自己的文件目录

#zookeeper 文件目录也换成自己的
case $1 in
        start) su root /usr/apache-zookeeper-3.7.1/bin/zkServer.sh start;;
        stop) su root /usr/apache-zookeeper-3.7.1/bin/zkServer.sh stop;;
        status) su root /usr/apache-zookeeper-3.7.1/bin/zkServer.sh status;;
        restart) su root /usr/apache-zookeeper-3.7.1/bin/zkServer.sh restart;;
        print-cmd) su root /usr/apache-zookeeper-3.7.1/bin/zkServer.sh print-cmd;;
        test)  echo "test good";;
        *) echo "require start|stop|status|restart|print-cmd" ;;
esac
:set ff=unix+  

#最后一句:set ff=unix+是设置文件格式,如果文件格式不正确,则开机启动不了,如果编辑器可以设置文件格式为unix,则可以注释掉最后一句

保存文件

修改目标目录的权限 chmod -R 777  /目标目录

添加开机启动

chkconfig --add zookeeper

查看是否添加成功

chkconfig --list

 

 

 

如果存在说明添加成功

reboot 重启 试试

开机启动不了的原因请排查:

原因1:目标目录的执行权限不够

原因2:要执行的脚本编码格式不正确

 目前我遇到的是上面两个原因

如果哪地方写的不正确,请大佬指正,谢谢!

posted @ 2023-04-12 11:56  Seamless  阅读(67)  评论(0编辑  收藏  举报