我在服务器的Docker容器中运行RabbitMQ服务和Celery。Worker是通过RabbitMQ连接到服务器的芹菜实例。
我这样设置并运行RabbitMQ:
sudo service rabbitmq-server start
rabbitmqctl add_user bunny password
rabbitmqctl add_vhost bunny_host
rabbitmqctl set_permissions -p bunny_host bunny ".*" ".*" ".*"
这有一个问题:如果一个工作者试图在正在启动的服务和正在创建并被授予权限的bunny用户之间进行连接,那么该工作者的芹菜实例将终止。
我试着把它添加到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
但是当我在容器中重新启动rabbitmqserver服务时,用户bunny并不存在。
(如果我尝试在服务未运行时使用rabbitmqctl添加用户,它会出错。(
任何帮助都将不胜感激。
在构建期间不能运行rabbitmqctl。相反,您可以通过使用引导文件来实现同样的目的。你需要像下面的片段一样更新你的文件
Dockerfile
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": []
}