一、有兩台服務器,一台centos6,一台centos8。centos6中配置了開機啟動腳本rc.local,理所當然的在centos8中也照樣配置了,結果.....Centos8中的rc.local並未啟動。
二、首先執行一條檢查命令:
systemctl status rc-local
發現它的狀態是:Active: inactive (dead) 未激活
這是什么原因?
在Centos系統中,我們運維一般在/etc/rc.d/rc.local寫入開機需要運行的命令,就可以實現系統開機啟動過程,啟動所需的命令,這是Centos5-6的常規做法,但是在Centos7-8采用了systemd技術,開機不會運行init進程,但是為了兼容Centos5-6版本,新版本中提供了一個rc-local的systemc服務,可以通過啟動此服務,實現rc.local文件中設置的啟動程序開機啟動。
所以設置一下:
1、將 rc.local 文件設置為可執行文件:
chmod +x /etc/rc.d/rc.local
2、在 /usr/lib/systemd/system/rc-local.service 結尾加上:
[Install]
WantedBy=multi-user.target
3、設置為開機啟動
systemctl enable rc-local
完成。
三、來看一下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.
意思是:
添加此文件是出於兼容性目的
最好創建自己的systemd服務或udev規則來在引導期間運行腳本,而不是使用這個文件。
與以前的版本不同,由於在引導期間並行執行,此腳本將不會在所有其他服務之后運行。
請注意,您必須運行CHMOD+X/ETC/RC D/rc.本地'以確保在引導期間執行此腳本。
創建啟動服務傳送門:https://www.cnblogs.com/hunttown/p/14872071.html