制作开机启动脚本

就以zookeeper的脚本启动作为例。

1.在/etc/init.d文件夹下面创建zookeeper文件

1 cd /etc/init.d
2 touch zookeeper
3 chmod +x zookeeper

2.在文件中附加如下内容

 1 #!/bin/bash
 2 #chkconfig:2345 20 90
 3 #description:zookeeper
 4 #processname:zookeeper
 5 case $1 in
 6           start) su root /usr/local/sw/zookeeper/bin/zkServer.sh start;;
 7           stop) su root /usr/local/sw/zookeeper/bin/zkServer.sh stop;;
 8           status) su root /usr/local/sw/zookeeper/bin/zkServer.sh status;;
 9           restart) su root /usr/local/sw/zookeeper/bin/zkServer.sh restart;;
10           *)  echo "require start|stop|status|restart"  ;;
11 esac

此时就可以通过
 service zookeeper restart 
来进行重启等操作;
3.实现开机启动

1 chkconfig -add zookeeper(centos7早期版本)
2 systemctl enable zookeeper(centos7)
原文地址:https://www.cnblogs.com/xiashiwendao/p/7866137.html