gpt4 book ai didi

docker - 在RabbitMQ不活跃时如何添加RabbitMQ用户

转载 作者:行者123 更新时间:2023-12-02 18:26:45 24 4
gpt4 key购买 nike

我在服务器的Docker容器中运行RabbitMQ服务和Celery。 worker 是通过RabbitMQ连接到服务器的celery实例。

我像这样设置并运行RabbitMQ:

sudo service rabbitmq-server start
rabbitmqctl add_user bunny password
rabbitmqctl add_vhost bunny_host
rabbitmqctl set_permissions -p bunny_host bunny ".*" ".*" ".*"

这有一个问题:如果工作人员尝试在正在启动的服务与正在创建的兔子用户之间建立连接并获得许可,则该工作人员的celery实例将终止。

我尝试将其添加到服务器的Dockerfile中,以在“实时”启动之前添加用户:
RUN sudo service rabbitmq-server start && \
rabbitmqctl add_user bunny password && \
rabbitmqctl add_vhost bunny_host && \
rabbitmqctl set_permissions -p bunny_host bunny ".*" ".*" ".*" && \
sudo service rabbitmq-server stop

但是,当我在容器内重新启动Rabbitmq-server服务时,用户兔子不存在。

(如果在服务未运行时尝试使用rabbitmqctl添加用户,则会出错。)

任何帮助将非常感激。

最佳答案

您不能在构建期间运行rabbitmqctl。相反,您可以通过使用引导文件来实现相同目的。您需要像下面的代码片段一样更新文件

Docker文件

FROM rabbitmq:3.6.11-management-alpine
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chmod 666 /etc/rabbitmq/*

rabbitmq.config
[
{
rabbit,
[
{ loopback_users, [] }
]
},
{
rabbitmq_management,
[
{ load_definitions, "/etc/rabbitmq/definitions.json" }
]
}
].


definitions.json
{
"rabbit_version": "3.6.14",
"users": [
{
"name": "user",
"password_hash": "0xZBvBD2JOGWrVO84nZ62EJuQIRehcILEiPVFB9mD4zhFcAo",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/"
}
],
"permissions": [
{
"user": "community",
"vhost": "/",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [],
"global_parameters": [
{
"name": "cluster_name",
"value": "rabbit@rabbitmq"
}
],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}

关于docker - 在RabbitMQ不活跃时如何添加RabbitMQ用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60547379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com