LINUX系统中设置开机自动执行命令

###

1、开机自动执行命令配置文件位置

[root@wx-local01 ~]# cd  /etc/rc.d/


[root@wx-local01 rc.d]# ls -l  /etc/rc.d/
总用量 4
drwxr-xr-x. 2 root root 107 9月   5 10:40 init.d
drwxr-xr-x. 2 root root  45 11月 17 2020 rc0.d
drwxr-xr-x. 2 root root  45 11月 17 2020 rc1.d
drwxr-xr-x. 2 root root  45 11月 17 2020 rc2.d
drwxr-xr-x. 2 root root  72 5月  26 14:02 rc3.d
drwxr-xr-x. 2 root root  72 5月  26 14:02 rc4.d
drwxr-xr-x. 2 root root  72 5月  26 14:02 rc5.d
drwxr-xr-x. 2 root root  45 11月 17 2020 rc6.d
-rwxr-xr-x. 1 root root 881 5月  27 16:06 rc.local
[root@wx
-local01 rc.d]# tree /etc/rc.d/ /etc/rc.d/ ├── init.d │ ├── functions │ ├── mysql -> /home/wx/mysql/support-files/mysql.server │ ├── netconsole │ ├── network │ ├── README │ └── syschronzed_date ├── rc0.d │ ├── K50netconsole -> ../init.d/netconsole │ └── K90network -> ../init.d/network ├── rc1.d │ ├── K50netconsole -> ../init.d/netconsole │ └── K90network -> ../init.d/network ├── rc2.d │ ├── K50netconsole -> ../init.d/netconsole │ └── S10network -> ../init.d/network ├── rc3.d │ ├── K50netconsole -> ../init.d/netconsole │ ├── S10network -> ../init.d/network │ └── S63syschronzed_date -> ../init.d/syschronzed_date ├── rc4.d │ ├── K50netconsole -> ../init.d/netconsole │ ├── S10network -> ../init.d/network │ └── S63syschronzed_date -> ../init.d/syschronzed_date ├── rc5.d │ ├── K50netconsole -> ../init.d/netconsole │ ├── S10network -> ../init.d/network │ └── S63syschronzed_date -> ../init.d/syschronzed_date ├── rc6.d │ ├── K50netconsole -> ../init.d/netconsole │ └── K90network -> ../init.d/network └── rc.local 8 directories, 24 files

2、设置开机自启动命令

[root@wx-local01 rc.d]# vim /etc/rc.d/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 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

#开机执行脚本启动harbor
sh /scripts/shell/start_harbor/power_on_self_starting_harbor.sh

3、设置执行权限【不设置执行权限,启动后不执行文件中内容】

[root@wx-local01 rc.d]# chmod +x /etc/rc.d/rc.local

###

原文地址:https://www.cnblogs.com/faithH/p/15228832.html