我无法从自己的自定义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-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文件中更改什么才能允许admin用户从远程机器连接?
执行docker compose -f docker-compose.yml up -d
后,我尝试连接到rabbitmsq容器并执行以下操作:
$ docker exec -it rabbitmq-1 bash
$ rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
型
由于某种原因,它没有工作,但无论如何,这似乎是一个糟糕的方式来处理这个问题
1条答案
按热度按时间rkkpypqq1#
根据文件:
默认情况下,禁止
guest
用户从远程主机连接。它只能通过以太网接口(即localhost
)连接。Bitnami RabbitMQ镜像为其默认用户实现了相同的机制。如果你进入你的容器并获取位于
/etc/rabbitmq/rabbitmq.conf
的配置文件的内容,你会看到这些行:字符串
这将阻止您在未通过
localhost
连接的情况下登录到admin
用户。你有两个选择:
我还将删除
rabbitmq
服务的RABBITMQ_USERNAME
和RABBITMQ_PASSWORD
环境变量,它们已经在.env
文件中定义,以及镜像不支持的RABBITMQ_HOST
。