centos7 linux 开机自启,开机时启动自定义脚本sh

linux 开机启动自定义的脚本程序方法有不少,下面介绍通过rc.local实现

参考这篇文章

https://blog.csdn.net/qq_41337034/article/details/110798071?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-110798071-blog-118198660.pc_relevant_antiscanv2&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-110798071-blog-118198660.pc_relevant_antiscanv2&utm_relevant_index=1

vi /etc/rc.d/rc.local 最下面添加自己要启动的脚本程序
注意:如果是启动java的脚本,一定要用JAVA_HOME的绝对路径

例如:下面的添加了开机执行nacos启动脚本

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local


#self
/home/nacos/nacos/bin/startup.sh -m standalone

保存退出后,添加权限

chmod +x /etc/rc.d/rc.local

reboot 重启系统后会执行添加的脚本