尝试 运行 Rabbitmq 时连接被拒绝

Connection refused when trying to run Rabbitmq

最近我在 Ubuntu 14 上安装了 Rabbitmq 3.6.2,但是每当我 运行 rabbitmq-server 命令时它都会给我错误:

{error_logger,{{2016,7,5},{13,45,12}},"Protocol: ~tp: register/listen error: ~tp~n",["inet_tcp",econnrefused]}
{error_logger,{{2016,7,5},{13,45,12}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.21.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6,[{file,"gen_server.erl"},{line,320}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}},{ancestors,[net_sup,kernel_sup,<0.10.0>]},{messages,[]},{links,[#Port<0.93>,<0.18.0>]},{dictionary,[{longnames,false}]},{trap_exit,true},{status,running},{heap_size,376},{stack_size,27},{reductions,805}],[]]}
{error_logger,{{2016,7,5},{13,45,12}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfargs,{net_kernel,start_link,[[rabbitmqprelaunch1853,shortnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
{error_logger,{{2016,7,5},{13,45,12}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}},{offender,[{pid,undefined},{name,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
{error_logger,{{2016,7,5},{13,45,12}},crash_report,[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.9.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,"application_master.erl"},{line,133}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}},{ancestors,[<0.8.0>]},{messages,[{'EXIT',<0.10.0>,normal}]},{links,[<0.8.0>,<0.7.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,376},{stack_size,27},{reductions,117}],[]]}
{error_logger,{{2016,7,5},{13,45,12}},std_info,[{application,kernel},{exited,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}}},{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}}},{kernel,start,[normal,[]]}}}"}

我检查了 iptables 里面没有规则。我确定 rabbitmq 不是 运行ning 并且端口可用。我不是 linux 大师,所以不知道去哪里搜索。

更新:

/etc/rabbitmq文件夹是空的,可能是因为没有用apt-get配置完成(也没有rabbitmq-env.conf):

Setting up rabbitmq-server (3.6.2-1) ...
* Starting message broker rabbitmq-server
* FAILED - check /var/log/rabbitmq/startup_\{log, _err\} [fail]
invoke-rc.d: initscript rabbitmq-server, action "start" failed.
dpkg: error processing package rabbitmq-server (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
rabbitmq-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

我的 ifconfig 看起来像这样(出于隐私原因在 ip 地址中添加了 xx):

 lo Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:56 errors:0 dropped:0 overruns:0 frame:0
      TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:2800 (2.8 KB)  TX bytes:2800 (2.8 KB)

 venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
      inet addr:127.0.0.2  P-t-P:127.0.0.2  Bcast:0.0.0.0  Mask:255.255.255.255
      UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
      RX packets:7323 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8256 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:919045 (919.0 KB)  TX bytes:1688814 (1.6 MB)

 venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
      inet addr:185.xx.xx.176  P-t-P:185.xx.xx.176  Bcast:185.xx.xx.176  Mask:255.255.255.255
      UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1

谢谢!

查看您的环回接口,您似乎在您的机器上禁用了 IPv6(没有 inet6 条目)。

现在,根据 this bug epmd 不支持 IPv6,因此他们对其进行了修补,但现在 需要 启用 IPv6 才能启动(查看评论 #16 和 #17)。

由于该错误没有其他 activity,我建议尝试在您的计算机上启用 IPv6。

可能的解决方法是使用 IPV4-mapped IPV6 address.

在您的 /etc/rabbitmq/rabbitmq-env.conf 中添加以下行:

ERL_EPMD_ADDRESS=::ffff:127.0.1.1

旧答案

您的错误有很多不同的可能根本原因。我假设您将 RabbitMq 配置为使用 IPv6 地址,或者您有一些没有 IPv4 的奇怪网络配置。

我认为值得尝试编辑 /etc/rabbitmq/rabbitmq-env.conf 并添加:

RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-proto_dist inet6_tcp"

如果不行,请post/etc/rabbitmq/rabbitmq-env.conf还有什么输出ifconfig,请

解决方法是从官方网站下载最新的 ErLang:

https://www.erlang-solutions.com/resources/download.html

我已经为 Ubuntu Precise 下载了 v19,现在运行良好。