1. 程式人生 > >centos7設置rc.local開機執行命令

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

roo chmod tst pmd nec servers 通過 不執行 systemctl

在Centos7下,rc.local文件,開機默認是不執行的

它是個軟鏈接

[root@data-1-1 ~]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Apr  8 17:11 /etc/rc.local -> rc.d/rc.local

  

實際文件不具備執行權限,設置開機啟動

[root@data-1-1 ~]# ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 524 Jun 20 09:12 /etc/rc.d/rc.local
[root@data-1-1 ~]# chmod +x /etc/rc.d/rc.local

  

腳本裏加入開機執行命令的腳本

[root@data-1-1 ~]# tail -2 /etc/rc.local 
systemctl stop keepalived
/etc/init.d/haproxy stop
[root@data-1-1 ~]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Apr  8 17:11 /etc/rc.local -> rc.d/rc.local
[root@data-1-1 ~]# 

  

之前此機器部署安裝了haproxy和Keepalived
重啟機器測試。haproxy和Keepalived開機之後被關閉。通過開機執行命令方式

[root@data-1-1 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      828/sshd            
tcp6       0      0 :::22                   :::*                    LISTEN      828/sshd            
[root@data-1-1 ~]# ps -ef |grep keep
root       942   892  0 09:17 pts/0    00:00:00 grep --colour=auto keep
[root@data-1-1 ~]# 

 

其它部分,和本文不相幹 

查看所有開機啟動的服務

[root@linux-node1 ~]# systemctl list-units --type=service
禁用epmd
systemctl stop [email protected]
systemctl stop [email protected]

  

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