1. 程式人生 > >CentOS7添加需要開機啟動的腳本

CentOS7添加需要開機啟動的腳本

centos7 開機腳本

1、修改開機腳本添加文件的權限

[[email protected] ~]# 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.
touch /var/lock/subsys/local
說明:如上可知,在CentOS7中,/etc/rc.d/rc.local文件的權限被降低了,開機的時候執行在自己的腳
本是不能啟動的,所有需要添加可執行的權限
[[email protected]
/* */ ~]# ls -l /etc/rc.d/rc.local -rw-r--r--. 1 root root 473 Nov 7 2016 /etc/rc.d/rc.local [[email protected] ~]# chmod +x /etc/rc.d/rc.local

2、添加一個清空iptables策略的開機腳本

[[email protected] ~]# mkdir -p /shells/
[[email protected] ~]# vim /shells/clean_iptables.sh
#!/bin/bash
/usr/sbin/iptables -F
/usr/sbin/iptables -X
/usr/sbin/iptables -Z
/usr/sbin/setenforce 0
[[email protected]
/* */ ~]# chmod +x /shells/clean_iptables.sh [[email protected] ~]# vim /etc/rc.d/rc.local # 添加需要開機啟動的腳本: /bin/sh /shells/clean_iptables.sh>/dev/null 2>&1

通過以上操作,就可以像CentOS6一樣添加開機腳本了


本文出自 “冰凍vs西瓜” 博客,請務必保留此出處http://molewan.blog.51cto.com/287340/1926938

CentOS7添加需要開機啟動的腳本