开机自启动centos7来自https://zhuanlan.zhihu.com/p/35402730

https://blog.csdn.net/aaooooo/article/details/75650952

https://blog.csdn.net/qq513165077/article/details/78692951

https://blog.csdn.net/chenxiabinffff/article/details/51374635

https://www.cnblogs.com/startcentos/p/6147444.html

https://www.jianshu.com/p/8a5d968afc7f

http://www.bubuko.com/infodetail-2234008.html

https://www.landui.com/help/show-5304.html

https://zhuanlan.zhihu.com/p/35402730

https://www.cnblogs.com/startcentos/p/6147444.html

1. 编写脚本autostart.sh,脚本内容如下:

 (不要有空格换行,如果一次不成功删除重新编辑设置程序,先root用户创建autostart.sh 编辑添加如下代码,在添加的服务启动 是在命令行中运行,如果可以运行成功例如

/usr/tomcat/bin/startup.sh start  在命令行运行正常用命令启动的 /usr/tomcat/bin/startup.sh start  &

#!/bin/sh
#chkconfig: 2345 80 90
#description: 开机自启动脚本

# 执行后台服务启动
/usr/tomcat/bin/startup.sh start &
/usr/zookeeper/bin/zkServer start &

脚本第一行 “#!/bin/sh” 告诉系统使用的shell;
脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90);
脚本第三行 表示的是服务的描述信息,要有“:”,否则不起作用

注意:

  • 第二行和第三行必写,否则会出现如“服务 autostart.sh 不支持 chkconfig”错误。
  • 执行命令必须是绝对路径引用。

2. 将写好的autostart.sh脚本移动到/etc/rc.d/init.d/目录下

3. 给脚本赋可执行权限

cd /etc/rc.d/init.d/
chmod +x autostart.sh

4. 添加脚本到开机自动启动项目中

chkconfig --add autostart.sh
chkconfig autostart.sh on

reboot 查看服务是否开机启动

 5.查看程序时()

ps -ef|grep tomcat

显示一条以上只有如下一条,没有实现开机自启动

root   5083  4986  0  15:52  pts/0   00:00:00   grep  --color=auto tomcat (ps -ef|grep tomcat自己的进程)

ps -ef|grep zookeeper

显示一条以上只有如下一条,没有实现开机自启动

root   5083  4986  0  15:52  pts/0   00:00:00   grep  --color=auto zookeeper(ps -ef|grep tomcat自己的进程)

原文地址:https://www.cnblogs.com/miaoer/p/8973199.html