RabbitMQ远程不能访问问题的解决

本文指导如何在RabbitMQ中配置远程登录权限,包括添加用户、授权访问及通过IP地址远程访问的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚刚安装的RabbitMQ-Server-3.3.5,并且也已经开启了Web管理功能,但是现在存在一个问题:

出于安全的考虑,guest这个默认的用户只能通过http://localhost:15672 来登录,不能使用IP地址登录,也就是不能远程访问,这对于服务器上没有安装桌面的情况是无法管理维护的。

RabbitMQ远程不能访问问题的解决RabbitMQ远程不能访问问题的解决

要解决这个问题需要配置远程登录权限,这里通过配置文件来实现远程访问。

CentOS 5.6 安装RabbitMQ http://www.linuxidc.com/Linux/2013-02/79508.htm

RabbitMQ客户端C++安装详细记录 http://www.linuxidc.com/Linux/2012-02/53521.htm

用Python尝试RabbitMQ http://www.linuxidc.com/Linux/2011-12/50653.htm

RabbitMQ集群环境生产实例部署 http://www.linuxidc.com/Linux/2012-10/72720.htm

Ubuntu下PHP + RabbitMQ使用 http://www.linuxidc.com/Linux/2010-07/27309.htm

在CentOS上安装RabbitMQ流程 http://www.linuxidc.com/Linux/2011-12/49610.htm

这里主要介绍Unix和Windows的配置文件修改。

一、Windows

    Windows环境下默认配置文件为目录/%RabbitMQ Server%/rabbitmq_server-3.3.5/etc下的rabbitmq.config.example文件,我们可以直接在这个文件中修改(可以不用去设置环境变量了),也可以自己再新建一个rabbitmq.config文件,然后把这个文件路径配置到环境变量中,这里介绍就直接修改rabbitmq.config.example文件。

    注意:修改之前,需要先停止RabbitMQ服务(rabbitmq-service stop 、rabbitmq-service install、rabbitmq-service start 【windows中的停止、安装、启动命令】)!!不然是不能保存的!!!

配置之前需要先添加用户,用于外网的访问,可以使用命令行来实现添加用户,需要在RabbitMQ的安装目录sbin目录下执行:


duanwf@master:/opt/rabbitmq_server-3.3.5/sbin$ rabbitmqctl add_user admin admin

    也可以通过web管理页面来添加用户和密码,使用guest登录web管理页面http://localhost:15672,进入“admin”标签页,然后点击“Add a user ”,输入对用的帐号密码,然后选择用户角色(一定要选择):

RabbitMQ远程不能访问问题的解决

    为了授权该用户对VirtualHost"/" 的访问,用户添加之后,需要对该用户进行授权,不然运行会出现错误:

1 Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""}

详细错误日志为:

 java.io.IOException
 at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
 at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
 at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
 at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:766)
 at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:61)
 at com.asiainfo.mq.rabbitmq.rabbitmqtest.SendTest.main(SendTest.java:29)
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""}
 at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
 at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
 at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
 at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
 at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)
 ... 3 more
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to queue 'hello' in vhost '/' refused for user 'admin', class-id=50, method-id=10), null, ""}
 at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:473)
 at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:313)
 at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
 at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
 at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:533)

 

  操作过程为:在Admin标签页下点击新增的用户"admin",进入授权页面,默认直接点击"set permission"即可:

RabbitMQ远程不能访问问题的解决

用户以及授权添加完成之后,在rabbitmq.config.example文件中,添加以下内容,保存后重启RabbitMQ服务:

……
[
 {rabbit,
  [%%
  %% Network Connectivity
  %% ====================
  %%
  %% By default, RabbitMQ will listen on all interfaces, using
  %% the standard (reserved) AMQP port.
  %%
  {tcp_listeners, [5672]},
  {loopback_users, ["admin"]},
……
  ]}
].

在浏览器中输入http://192.168.0.124:15672实现通过IP地址访问,成功登录:

RabbitMQ远程不能访问问题的解决

测试用例见博文“RabbitMQ远程调用测试用例 http://www.linuxidc.com/Linux/2014-10/107916.htm

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值