Linux脚本开机自启动

linux.jpg

Linux脚本开机启动

Linux系统文件执行顺序

方式一 /etc/profile.d

将需要自启动的脚本放在 /etc/profile.d/ 目录下,将脚本添加执行权限。
需要注意的是,该方式的脚本必须为 .sh结尾,且每次远程连接服务器时都会启动一次该脚本

方式二 /etc/rc.local

在/etc/rc.local文件中加入需要执行的脚本启动命令,且将 /etc/rc.d/rc.local 添加执行权限。使用该方式只会在开机时执行脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
~]# more /etc/rc.local 
#!/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 service
#
# 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
sh /usr/local/prometheus/start.sh #添加的执行脚本