ADJ網路實驗室
打印

[介紹] 解決 CentOS 7 開機不啟動 rc.local

解決 CentOS 7 開機不啟動 rc.local

以前在 Redhat 及 CentOS 要設定開機自動執行的 Shell Script, 一般都會在檔案 /etc/rc.d/rc.local 加入需要執行的 Shell Script 或指令, 但在 CentOS 7 開始, /etc/rc.d/rc.local 預設權限改為 644, 即沒有執行權限, 為甚麼會這樣, 可以開啟 CentOS 7 的 /etc/rc.d/rc.local 看看, 裡面有 Redhat 的說明:
引用:


#!/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.


可以看到這個檔案在 RHEL 及 CentOS 7 只為了解決兼容性, Redhat 建議還是自行建立 systemd 服務或者 udev rules 較好, 如果真的需要使用 rc.local, 只要執行 chmod 給予 rc.local 可執行權限即可:
# chmod +x /etc/rc.d/rc.local

執行以上指令後, 下次開機便會自動執行 rc.local 內的指令或 Shell Script.





TOP

ARTERY.cn