添加开机后自动执行脚本

环境: centos

#开放端口
为了部署nginx http服务,开发80端口:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --sport 80 -j ACCEPT
service iptables save

说明: 如果以上执行 service iptables save 失败,显示 The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
这是因为 iptables的服务没有安装。
解决: yum install iptables-services

#开机自动执行脚本
step: 1
将以上命令写在 open_port.sh文件中。
放在某一路径下,比如 /home/user/temp/open_port.sh

step:2
将执行命令写在文件 /etc/rc.d/rc.local 中,即在 rc.local 文件最后加上:

sh /home/user/temp/open_port.sh

step 3:
给 /etc/rc.d/rc.local 文件添加可执行权限:

chmod +x /etc/rc.d/rc.local

之后再开机时,open_port.sh 脚本会被自动执行。

参考文章:
Centos 7 之service iptables save 指令使用失败的结局方案
https://blog.csdn.net/yelllowcong/article/details/78229862

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值