Bootstrap

rabbitmq延时插件安装以及启用

1.构建镜像直接安装

step1

mkdir -p /root/rabbit_Dockerfile
cd /root/rabbit_Dockerfile
vim Dockerfile

step2

FROM rabbitmq:management
# 设置时区为亚洲/上海
ENV TZ=Asia/Shanghai
# 安装 tzdata 包以便设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 将插件文件复制到 RabbitMQ 插件目录中
COPY rabbitmq_delayed_message_exchange-3.9.0.ez /plugins/rabbitmq_delayed_message_exchange.ez
# 启用插件
RUN rabbitmq-plugins enable --offline rabbitmq_delayed_message_exchange

step3

#!/bin/bash
#构建镜像
docker build -t delayed_message_rabbitmq .
#启动容器
docker run -d --name delayed_message_rabbitmq -p 5672:5672 -p 15672:15672  -v /etc/localtime:/etc/localtime delayed_message_rabbitmq
#睡眠10秒 为了等待rabbitmq完全启动
sleep 10s
#新增admin用户设置密码
docker exec delayed_message_rabbitmq rabbitmqctl add_user admin ${pwd}
# 设置admin 为超级用户
docker exec delayed_message_rabbitmq rabbitmqctl set_user_tags admin administrator
#设置admin 权限
docker exec delayed_message_rabbitmq rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
# 删除默认的rabbitmq 用户 guest
docker exec delayed_message_rabbitmq rabbitmqctl delete_user guest

2.已存在容器安装

step1 进入容器内部

docker exec -it 容器名称 /bin/bash

step2 查看插件是否存在

rabbitmq-plugins list
如果插件存在则直接启用
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
如果不存在则下载插件,下载地址:https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases

step3 将插件上传到宿主机root目录

然后复制到容器内部
docker cp 插件名称 容器名字:/opt/rabbitmq/plugins
然后执行 step1进入容器内部
然后执行
cd /opt/rabbitmq/plugins

rabbitmq-plugins enable rabbitmq_shovel rabbitmq_shovel_management

rabbitmq-plugins list

rabbitmq-plugins enable rabbitmq_delayed_message_exchange

针对容器中插件已存在情况的安装

方式一:

docker exec -it rabbitmq /bin/bash
---------------------------------
user@7b295c46c99d /: rabbitmq-plugins enable rabbitmq_management

方式二:

docker exec -it rabbitmq rabbitmq-plugins enable rabbitmq_management

;