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