服務器升級到CentOS7 要設置一個開機啟動的腳本...
直接使用 vi /etc/rc.d/rc.local 命令,編輯rc.local文件.
但重新啟動后發(fā)現(xiàn)沒有運行相應的腳本....
cat /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.
大致意思是說這個文件是為了兼容而設置的.
如果要使用開始啟動 建議使用systemd來建立自己的服務.
如果一定要使用 使用 chmod +x /etc/rc.d/rc.local 來增加權(quán)限進行運行.
即然說了不建議使用.我們就不用了.
使用 systemctl 來進行設置自己的服務 其實也非常簡單.
1:編輯啟動腳本. autostart.sh
注意 此autostart.sh的前三行一定是:
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
具體什么原因:參考:http://blog.chinaunix.net/uid-20521628-id-365862.html
2:把autostart.sh 放到 /etc/init.d/
3:運行:systemctl enable autostart.sh
4:reboot 啟動 腳本成功運行.
5:使用systemctl disable autostart.sh 可以關閉啟動.