在 Redhat / Centos 开机后, 如果想自动执行一些 shell script 或指令, 可以直接编辑 /etc/rc.local 档案.
注: RHEL 及 CentOS 7 默认不会启动 /etc/rc.local, 需要先执行以下指令才可以:
# chmod +x /etc/rc.local
以下是 /etc/rc.local 默认内容:
|
1 2 3 4 5 6 7 |
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local |
要加入自动执行指令或 shell script 十分简单, 只要直接加上要执行的指令即可, 例如我设定了每次开机会自动恢复 iptables 的设定, 便加入了 iptables-restore 指令:
|
1 2 3 4 5 6 7 8 |
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /sbin/iptables-restore < /root/iptables-save |
储存盘案后就完成了, 下次开机便会自动执行加入的指令.