linux rabbitmq

环境信息

  • Centos7 3.10.0-1160.45.1.el7
  • RabbitMQ 3.9.10

常见错误

RabbitMQ 启动失败

使用命令启动,报错

$ /sbin/rabbitmq-server -v
2023-04-26 10:02:47.621248+08:00 [noti] <0.146.0> Protocol 'inet_tcp': register/listen error: ehostunreach
2023-04-26 10:02:47.621248+08:00 [noti] <0.146.0>
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> supervisor: {local,net_sup}
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> errorContext: start_error
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> reason: {'EXIT',nodistribution}
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> offender: [{pid,undefined},
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> {id,net_kernel},
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> {mfargs,{net_kernel,start_link,
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> [[rabbit_prelaunch_21812@localhost,
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> shortnames],
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> false,net_sup_dynamic]}},
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> {restart_type,permanent},
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> {shutdown,2000},
2023-04-26 10:02:47.626643+08:00 [erro] <0.143.0> {child_type,worker}]

关键错误信息 Protocol 'inet_tcp': register/listen error: ehostunreach,根据提示,可能是某个地址不可达,rabbitmq 启动时需要连接 epmd ,默认端口为 4369,在本地测试连接此端口,发现不通 [1]

$ curl -v 127.0.0.1:4369
* About to connect() to 127.0.0.1 port 4369 (#0)
* Trying 127.0.0.1...
* No route to host
* Failed connect to 127.0.0.1:4369; No route to host
* Closing connection 0
curl: (7) Failed connect to 127.0.0.1:4369; No route to host

根据输出的错误可知,是因为 127.0.0.1 无法连接,检查 iptables 防火墙策略,发现未允许回环网卡访问,在 iptables 中添加以下规则允许回环网卡访问

/etc/sysconfig/iptables
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [9020367577:7010759848370]
-A INPUT -i lo -j ACCEPT

允许回环网卡访问后,重新测试连接 epmd ,可以正常连接,重新启动 rabbitmq-server 正常。

$ curl -v 127.0.0.1:4369
* About to connect() to 127.0.0.1 port 4369 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 4369 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:4369
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

脚注