bitnami/rabbitmq docker compose:普通登录被拒绝

问题描述 投票:0回答:1

我无法从我自己的自定义 python 应用程序连接到 RabbitMQ 服务器(使用 bitnami/rabbitmq:3.11 图像),并出现错误

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-1
 2023-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 文件中更改哪些内容以允许管理员用户从远程计算机进行连接?

执行后

docker compose -f docker-compose.yml up -d
我尝试连接到rabbitmsq容器并执行以下操作:

$ docker exec -it rabbitmq-1 bash

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

由于某种原因它不起作用,但无论如何这似乎是处理问题的一个坏方法

docker docker-compose rabbitmq bitnami
1个回答
0
投票

根据文档

默认情况下,禁止

guest
用户从远程主机进行连接。它只能通过环回接口进行连接(即
localhost
)。

Bitnami RabbitMQ 镜像为其默认用户实现了相同的机制。如果您进入容器并获取位于

/etc/rabbitmq/rabbitmq.conf
的配置文件的内容,您将看到这些行:

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

这会阻止您在未通过

admin
连接的情况下登录
localhost
用户。

您有两个选择:

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

我还会删除

RABBITMQ_USERNAME
服务的
RABBITMQ_PASSWORD
rabbitmq
环境变量(它们已在您的
.env
文件中定义),以及图像不支持的
RABBITMQ_HOST

© www.soinside.com 2019 - 2024. All rights reserved.