centos7設置rc.local開機執行命令


背景:自己的服務器放在家里,結果昨天早上跳槽了,12台虛擬機需要全部重啟,每個里面都有服務,需要手動起就很麻煩,

就給每個虛擬機寫腳本,開機的時候直接執行。

一開始把腳本放在/etc/bashrc里面的,但是執行的時候有些特殊

 

 然后改到rc.local中,具體如下:

[root@localhost logs]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 May 29 03:16 /etc/rc.local -> rc.d/rc.local
[root@localhost logs]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 May 12 11:45 /etc/rc.d/rc.local
[root@localhost logs]# vim /etc/rc.d/rc.local
[root@localhost logs]# chmod +x /etc/rc.d/rc.local
[root@localhost logs]# cat /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 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.

touch /var/lock/subsys/local


nohup sh /wgr/logs/start.sh > /dev/null 2&>1  &  

進行重啟,發現日志新增了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM