如何更正firewalld和docker/nginx的配置?
我有一个 CentOS 7 服务器,它运行了 600 多天,直到最近重新启动,之后传入的 Web 请求接收到 HTTP523(源无法访问)错误代码(通过 Cloudflare,如果这有区别?)除非我停止了 firewalld服务。没有firewalld,事情运行良好,但我不想让它被禁用!
我试过以各种顺序停止docker和firewalld重新启动它们,但523除非我停止,否则会发生相同的错误firewalld。
/var/log/firewalld 包含一些可能有帮助的警告:
WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-8acb606a3b50 -o br-8acb606a3b50 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).WARNING: AllowZoneDrifting is enabled. This is considered a n insecure configuration option. It will be removed in a future release. Please consider disabling it now.WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D PREROUTING -m addrtype --dst-type LOCAL -j DOCKER' failed: iptables v1.4.21: Couldn't load target 'DOCKER':No such file or directoryWARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D PREROUTING' failed: iptables: Bad rule (does a matching rule exist in that chain?).WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D OUTPUT' failed: iptables: Bad rule (does a matching rule exist in that chain?)WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -F DOCKER' failed: iptables: No chain/target/match by that name.
关于所需的任何手动配置/命令,我发现周围似乎存在相互矛盾的建议:
firewall-cmd --permanent --zone=trusted --add-interface=docker0在 CentOS 论坛上firewall-cmd --zone=trusted --remove-interface=docker0 --permanent在官方 Docker 文档中——这肯定与上述相反吗?- 一堆
firewall-cmd关于 Docker github 问题的手动命令——当然所有这些都不是必需的? - 这一个看起来很有希望-
nmcli,NetworkManager和firewall-cmd --permanent --zone=trusted --change-interface=docker0
我不完全了解br-8acb606a3b50接口的来源,或者我是否需要做任何事情来配置它以及docker0是否使用上述解决方案4.?多年来,它一直自动正常工作,直到重新启动!
firewalld现在是否需要一些魔法咒语(为什么?!)或者有什么方法可以让系统恢复到重新启动之前的正确自动/默认配置?
$ docker -v
Docker version 20.10.5, build 55c4c88
$ firewall-cmd --version
0.6.3
$ firewall-cmd --get-zones
block dmz docker drop external home internal public trusted work
回答
回顾一下聊天调查,这个特殊问题与 Docker 和容器无关。问题在于firewalld没有规则NGINX作为主机上容器的代理运行。解决方案是为 HTTP 和 HTTPS 流量添加永久的 firewalld 规则:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
像这样的警告消息:
警告:COMMAND_FAILED:'/usr/sbin/iptables -w10 -D FORWARD -i br-8acb606a3b50 -o br-8acb606a3b50 -j DROP'失败:iptables:错误规则(该链中是否存在匹配规则?)
... 可以在正常操作期间出现,当 Docker 尝试删除规则而不先检查其是否存在时。换句话说,即使有这样的警告,容器也可以顺利运行。