centos7设置rc.local开机执行命令
在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 epmd@0.0.0.0.socket systemctl stop epmd@0.0.0.0