使用Ansible安装部署nginx+php+mysql之配置iptables防火墙(0)
前提:
1、已配置好hosts文件且免密码登录
2、需要的yaml文件已上传到主控端
一、使用Ansible配置iptables
1、iptables.yaml文件
1 ---
2 - hosts: clong
3 remote_user: root
4 gather_facts: no
5 tasks:
6 # 停止系统自带的firewalld防火墙
7 - name: stop firewalld
8 service: name=firewalld state=stopped
9 # 卸载系统自带的firewalld防火墙
10 - name: remove firewalld
11 yum: name=firewalld state=absent
12 # 安装iptables防火墙
13 - name: install iptables
14 yum: name=iptables-services state=present
15 # 开启iptables防火墙
16 - name: enable iptables
17 service: name=iptables state=started enabled=yes
18 # 安装libselinux-python
19 - name: install libselinux-python
20 yum: name=libselinux-python state=present
21 # iptables防火墙配置文件放行80,3306端口
22 - name: copy iptables
23 copy: src=iptables dest=/etc/sysconfig/iptables backup=yes owner=root group=root mode=0600
24 notify: restart iptables
25 # 重启iptables防火墙
26 handlers:
27 - name: restart iptables
28 service: name=iptables state=restarted
2、iptables文件
1 # sample configuration for iptables service
2 # you can edit this manually or use system-config-firewall
3 # please do not ask us to add additional ports/services to this default configuration
4 *filter
5 :INPUT ACCEPT [0:0]
6 :FORWARD ACCEPT [0:0]
7 :OUTPUT ACCEPT [0:0]
8 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
9 -A INPUT -p icmp -j ACCEPT
10 -A INPUT -i lo -j ACCEPT
11 -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
12 -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
13 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
14 -A INPUT -j REJECT --reject-with icmp-host-prohibited
15 -A FORWARD -j REJECT --reject-with icmp-host-prohibited
16 COMMIT
分类:
Ansible
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)