配置 Docker 容器的 RabbitMQ

版权声明:版权归博主所有,转载请带上本文链接!联系方式:[email protected] https://blog.csdn.net/isea533/article/details/88036082

针对 rabbitmq 进行配置:

创建步骤如下。

1. 启动容器

docker run -d --hostname my-rabbit --name rabbitmq -p 8080:15672 \
 rabbitmq:3.7-management-alpine

2. 进入容器

docker exec -it rabbitmq /bin/sh

3. 启用插件

umask 0022; rabbitmq-plugins enable --offline \
 rabbitmq_auth_backend_http rabbitmq_auth_backend_cache rabbitmq_web_stomp

特别注意这里的 umask 0022;,只有这样配置,镜像才能读取插件配置,才能启动成功。

输出内容:

The following plugins have been configured:
  rabbitmq_auth_backend_cache
  rabbitmq_auth_backend_http
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_stomp
  rabbitmq_web_dispatch
  rabbitmq_web_stomp
Applying plugin configuration to rabbit@my-rabbit...
The following plugins have been enabled:
  rabbitmq_auth_backend_cache
  rabbitmq_auth_backend_http
  rabbitmq_stomp
  rabbitmq_web_stomp

set 7 plugins.
Offline change; changes will take effect at broker restart.

4. 配置 /etc/rabbitmq/rabbitmq.conf

在配置中追加:

auth_backends.1 = cache

# auth_backends.1 = http
auth_backends.2 = internal

auth_cache.cached_backend = http

auth_http.http_method   = post

auth_http.user_path = http://rabbitmq-auth:8080/auth/user
auth_http.vhost_path = http://rabbitmq-auth:8080/auth/vhost
auth_http.resource_path = http://rabbitmq-auth:8080/auth/resource
auth_http.topic_path = http://rabbitmq-auth:8080/auth/topic

auth_cache.cache_ttl = 60000

特别注意,后续需要提供 rabbitmq-auth 服务进行认证。

5. 退出容器提交

退出容器后,使用容器当前状态提交为新的镜像,参考命令如下:

docker commit rabbitmq 镜像名:版本

后续使用镜像时,就可以直接使用插件提供的功能了。

猜你喜欢

转载自blog.csdn.net/isea533/article/details/88036082