开机运行的系统文件

/etc/rc.d/rc.local是一开机就马上运行的脚本!系统一定会先开机后马上执行里面的任务!
由于/etc/rc.local是/etc/rc.d/rc.local的软连接,所以必须确保/etc/rc.local和/etc/rc.d/rc.local都有x权限(可执行权限)


vim /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 constrast 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

#这个文件是为了兼容性的问题而添加的。
#
#强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。
#
#与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。
#
#请记住,你必须执行“chmod +x /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 constrast 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
/usr/local/nginx/sbin/nginx

chmod +x /etc/rc.d/rc.local
systemctl start mariadb
systemctl enable mariadb
systemctl start php-fpm
systemctl enable php-fpm
------------------------------------------------------------------------------------------------------------------------------------
检查系统rc.local服务运行情况

systemctl | grep "rc.local"
# rc-local.service loaded active running /etc/rc.d/rc.local Compatibility
发现运行正常

随后查看rc.local文件

inux /etc/init.d和/etc/rc.d/rc.local的区别

/etc/init.d是个目录,这个目录里面用于放置shell脚本,注意是脚本,这些脚本是启动脚本,用于Linux中服务的启动、停止、重启,比如各种Linux中的服务都会有启动脚本放在这里,像是ssh服务的文件sshd就在这里面。而/etc/rc.d/rc.local是一个文件,这个文件用于用户自定义开机启动程序,也就是说用户可以把需要开机启动的程序、命令写入这个文件,这样就可以在系统启动时自动执行这个命令,比如把一个shell脚本的完整路径写入这个文件,那这个shell脚本就会在开机后自动执行。

扫描二维码关注公众号,回复: 6050914 查看本文章

ps -ef, top, netstat -an
md5sum

猜你喜欢

转载自www.cnblogs.com/summer2/p/10787822.html