天天看点

CentOS7添加需要开机启动的脚本

1、修改开机脚本添加文件的权限

<code>[root@LVS-RS02 ~]</code><code># cat /etc/rc.d/rc.local </code>

<code>#!/bin/bash</code>

<code># THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES</code>

<code>#</code>

<code># It is highly advisable to create own systemd services or udev rules</code>

<code># to run scripts during boot instead of using this file.</code>

<code># In contrast to previous versions due to parallel execution during boot</code>

<code># this script will NOT be run after all other services.</code>

<code># Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure</code>

<code># that this script will be executed during boot.</code>

<code>touch</code> <code>/var/lock/subsys/local</code>

<code>说明:如上可知,在CentOS7中,</code><code>/etc/rc</code><code>.d</code><code>/rc</code><code>.</code><code>local</code><code>文件的权限被降低了,开机的时候执行在自己的脚</code>

<code>本是不能启动的,所有需要添加可执行的权限</code>

<code>[root@LVS-RS02 ~]</code><code># ls -l /etc/rc.d/rc.local </code>

<code>-rw-r--r--. 1 root root 473 Nov  7  2016 </code><code>/etc/rc</code><code>.d</code><code>/rc</code><code>.</code><code>local</code>

<code>[root@LVS-RS02 ~]</code><code># chmod +x /etc/rc.d/rc.local</code>

2、添加一个清空iptables策略的开机脚本

<code>[root@LVS-RS02 ~]</code><code># mkdir -p /shells/</code>

<code>[root@LVS-RS02 ~]</code><code># vim /shells/clean_iptables.sh</code>

<code>/usr/sbin/iptables</code> <code>-F</code>

<code>/usr/sbin/iptables</code> <code>-X</code>

<code>/usr/sbin/iptables</code> <code>-Z</code>

<code>/usr/sbin/setenforce</code> <code>0</code>

<code>[root@LVS-RS02 ~]</code><code># chmod +x /shells/clean_iptables.sh</code>

<code>[root@LVS-RS02 ~]</code><code># vim /etc/rc.d/rc.local </code>

<code># 添加需要开机启动的脚本:</code>

<code>/bin/sh</code> <code>/shells/clean_iptables</code><code>.sh&gt;</code><code>/dev/null</code> <code>2&gt;&amp;1</code>

通过以上操作,就可以像CentOS6一样添加开机脚本了

本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1926938,如需转载请自行联系原作者