【问题标题】:Can not get remote access to RabbitMq server无法远程访问 RabbitMq 服务器
【发布时间】:2020-03-06 06:31:17
【问题描述】:

我无法远程访问 RabbitMq 服务器。当我在一台机器上执行此操作并连接到 localhost:15672 时,它可以工作,但是当我从远程机器上尝试时,它就不行了。

我已经创建了一个具有所有权限的用户并检查计算机上的 5672 端口是否正常工作(只是尝试从远程计算机连接到他)。另外,我尝试连接到 15672 端口,但没有结果。

credentials = pika.PlainCredentials(username= 'username', password='password')
parameters = pika.ConnectionParameters(host='188.19.100.226',
                                   port=5672,
                                   virtual_host= '/',
                                   credentials=credentials)

connection = pika.BlockingConnection(parameters=parameters)
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                  routing_key='hello',
                  body=hello)
print ("Sent!")
connection.close()

我希望看到 Sent!,但我没有收到:

ERROR:pika.adapters.utils.io_services_utils:Socket failed to connect: <socket.socket fd=7, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('192.168.100.2', 44752)>; error=111 (Connection refused)
ERROR:pika.adapters.utils.connection_workflow:TCP Connection attempt failed: ConnectionRefusedError(111, 'Connection refused'); dest=(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('188.19.100.226', 5672))
ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure: AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused')
ERROR:pika.adapters.utils.connection_workflow:AMQP connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None.
ERROR:pika.adapters.utils.connection_workflow:AMQPConnectionWorkflow - reporting failure: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None
ERROR:pika.adapters.blocking_connection:Connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None
ERROR:pika.adapters.blocking_connection:Error in _create_connection().
Traceback (most recent call last):
  File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
Traceback (most recent call last):
  File "/home/roman/PycharmProjects/trrp2/send.py", line 52, in <module>
    connection = pika.BlockingConnection(parameters=parameters)
  File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 359, in __init__
    self._impl = self._create_connection(parameters, _impl_class)
  File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError

【问题讨论】:

标签: python linux rabbitmq ip pika


【解决方案1】:

你需要配置rabbitmq来监听本地主机以外的其他接口。 要接受来自所有接口的连接,请收听 0.0.0.0

https://www.rabbitmq.com/networking.html#interfaces

【讨论】:

  • 嗯,我没有rabbitmq.conf文件,只有两个文件:rabbitmq-env.conf和enabled-plugins
  • 你需要添加一个。我认为 rabbitmq 有默认设置让你开始,但他们不打开端口 I. 一种不安全的方式。除非你明确地这样做。
  • 但是端口是开放的。我尝试通过远程终端直接连接到它,它成功了
  • 我指的不是端口。我指的是监听界面。 rabbitmq 的默认监听接口是 localhost,这意味着它不会接受来自除 localhost 之外的任何地方的连接。如果你将接口配置设置为 listeners.tcp.1 = :::5672 然后你告诉 rabbitmq 监听所有接口,你应该可以从另一台机器连接
  • 所有接口默认打开
猜你喜欢
  • 1970-01-01
  • 2022-01-12
  • 2013-03-17
  • 2022-06-27
  • 1970-01-01
  • 2015-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多