bitnami/rabbitmq docker compose:plain login rejected

lnvxswe2  于 11个月前  发布在  RabbitMQ
关注(0)|答案(1)|浏览(183)

我无法从自己的自定义Python应用程序连接到RabbitMQ服务器(使用bitnami/rabbitmq:3.11 image),错误为user 'admin' can only connect via localhost
我的docker-compose.yml:

version: "3.9"

x-logging: &default-logging
  driver: journald

services:
  python_app_example:
    image: python_app
    logging: *default-logging
    expose:
      - "32000"
    environment:
      - MINERS_RABBITMQ_URL=amqp://${RABBITMQ_USERNAME}:${RABBITMQ_PASSWORD}@${RABBITMQ_HOST}:${RABBITMQ_PORT}//
    command: python3 -m python_app.app
    healthcheck:
      test: [ "CMD", "nc", "-z", "-v", "localhost", "32000"]
      interval: 3s
      timeout: 3s
      retries: 50
    depends_on:
      rabbitmq:
        condition: service_healthy
    networks:
      - rabbitmq

  rabbitmq:
    image: bitnami/rabbitmq:3.11
    logging: *default-logging
    ports:
      - "29998:5672"
      - "15672:15672"
    environment:
      - RABBITMQ_HOST=rabbitmq
      - RABBITMQ_USERNAME
      - RABBITMQ_PASSWORD
      - RABBITMQ_PLUGINS=rabbitmq_management
      - RABBITMQ_SECURE_PASSWORD=yes
      - RABBITMQ_LOGS=-
    volumes:
      - 'rabbitmq_data:/bitnami/rabbitmq/mnesia'
    healthcheck:
      test: rabbitmq-diagnostics -q ping
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - rabbitmq

networks:
  miners_server:
  rabbitmq:

volumes:
  rabbitmq_data:
    driver: local

字符串
我的.env文件:

RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=admin
RABBITMQ_PASSWORD=admin


python_app_example失败,出现错误:Connection to amqp://admin:******@rabbitmq:5672// closed. ... ProbableAuthenticationError: ('ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.',)
以下是rabbitmq日志docker logs rabbitmq-12023-12-11 17:06:03.755693+00:00 [info] <0.2916.0> accepting AMQP connection <0.2916.0> (172.28.0.3:44366 -> 172.28.0.2:5672) 2023-12-11 17:06:03.756757+00:00 [error] <0.2916.0> Error on AMQP connection <0.2916.0> (172.28.0.3:44366 -> 172.28.0.2:5672, state: starting): 2023-12-11 17:06:03.756757+00:00 [error] <0.2916.0> PLAIN login refused: user 'admin' can only connect via localhost 2023-12-11 17:06:03.756857+00:00 [info] <0.2916.0> closing AMQP connection <0.2916.0> (172.28.0.3:44366 -> 172.28.0.2:5672)
我应该在我的docker compose文件中更改什么才能允许admin用户从远程机器连接?
执行docker compose -f docker-compose.yml up -d后,我尝试连接到rabbitmsq容器并执行以下操作:

$ docker exec -it rabbitmq-1 bash

$ rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"


由于某种原因,它没有工作,但无论如何,这似乎是一个糟糕的方式来处理这个问题

rkkpypqq

rkkpypqq1#

根据文件:
默认情况下,禁止guest用户从远程主机连接。它只能通过以太网接口(即localhost)连接。
Bitnami RabbitMQ镜像为其默认用户实现了相同的机制。如果你进入你的容器并获取位于/etc/rabbitmq/rabbitmq.conf的配置文件的内容,你会看到这些行:

default_user = admin
default_pass = admin
...
loopback_users.admin = true

字符串
这将阻止您在未通过localhost连接的情况下登录到admin用户。
你有两个选择:

  • 使用没有这种限制的official RabbitMQ image
  • 通过从Bitnami映像创建自定义映像,直接在容器中重写配置。

我还将删除rabbitmq服务的RABBITMQ_USERNAMERABBITMQ_PASSWORD环境变量,它们已经在.env文件中定义,以及镜像不支持的RABBITMQ_HOST

相关问题