Docker 启动RabbitMQ 服务,外部不能正常访问
Posted 在奋斗的大道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker 启动RabbitMQ 服务,外部不能正常访问相关的知识,希望对你有一定的参考价值。
今天在总结RabbitMQ消息队列服务器时,遇到一个小问题:服务器拉取RabbitMQ 服务器镜像正常,启动RabbitMQ 镜像服务正常,但通过外部访问RabbitMQ 管理端提示无法访问。
第一步:检查服务器的防火墙状态(firewalld)
核心指令:
systemctl status firewalld.service // 查看防火墙状态
systemctl stop firewalld.service //关闭防火墙状态
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor pr
Active: inactive (dead) since 六 2022-06-18 01:33:04 CST; 1 months 13 days ag
Docs: man:firewalld(1)
Main PID: 30715 (code=exited, status=0/SUCCESS)
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAILED:
6月 18 01:33:02 localhost.localdomain systemd[1]: Stopping firewalld - dynamic f
6月 18 01:33:04 localhost.localdomain systemd[1]: Stopped firewalld - dynamic fi
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 六 2022-06-18 01:33:04 CST; 1 months 13 days ago
Docs: man:firewalld(1)
Main PID: 30715 (code=exited, status=0/SUCCESS)
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 00:04:01 localhost.localdomain firewalld[30715]: WARNING: COMMAND_FAI...
6月 18 01:33:02 localhost.localdomain systemd[1]: Stopping firewalld - dynam...
6月 18 01:33:04 localhost.localdomain systemd[1]: Stopped firewalld - dynami...
Hint: Some lines were ellipsized, use -l to show in full.
结果:问题还是没有解决
2、检查防火墙日志
核心指令:tail /var/log/firewalld
[root@localhost log]# tail /var/log/firewalld
2022-06-18 00:04:01 WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -F DOCKER' failed: iptables: No chain/target/match by that name.
2022-06-18 00:04:01 WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -X DOCKER' failed: iptables: No chain/target/match by that name.
2022-06-18 00:04:01 WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -F DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name.
2022-06-18 00:04:01 WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t filter -X DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name.
2022-06-18 00:04:01 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?).
重点关注错误日志:2022-06-18 00:04:01 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?).
google 和百度后得知:docker默认会自动添加iptables rule
解决办法:docker.service禁止修改iptables
3、修改docker.service 服务,禁用修改iptables.
[root@localhost system]# vi /lib/systemd/system/docker.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --iptables=false
在ExecStart 添加 --iptables=false.
重新启动docker 容器服务:
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl restart docker
重新启动RabbitMQ 服务:
[root@localhost system]# docker restart 4b0032
4b0032
[root@localhost system]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b0032878886 6c3c2a225947 "docker-entrypoint.s…" 47 hours ago Up 3 seconds 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq
RabbitMQ服务管理界面,能够正常方法。
以上是关于Docker 启动RabbitMQ 服务,外部不能正常访问的主要内容,如果未能解决你的问题,请参考以下文章