Docker Compose部署Rabbitmq(脚本下载延迟插件)
整个工具的代码都在Gitee或者Github地址内
gitee:solomon-parent: 这个项目主要是总结了工作上遇到的问题以及学习一些框架用于整合例如:rabbitMq、reids、Mqtt、S3协议的文件服务器、mongodb
github:GitHub - ZeroNing/solomon-parent: 这个项目主要是总结了工作上遇到的问题以及学习一些框架用于整合例如:rabbitMq、reids、Mqtt、S3协议的文件服务器、mongodb
1.新增data文件夹
2.新增docker-compose.yml文件
version: '3.8'
services:
rabbitmq:
image: rabbitmq:management
container_name: rabbitmq
ports:
- "15672:15672"
- "5672:5672"
volumes:
- ./start-rabbitmq-with-plugin.sh:/usr/local/bin/start-rabbitmq-with-plugin.sh
- ./data:/usr/etc/rabbitmq/data
- /etc/localtime:/etc/localtime # 容器与宿主机时间同步
command: ["/bin/bash", "-c", "chmod +x /usr/local/bin/start-rabbitmq-with-plugin.sh && /usr/local/bin/start-rabbitmq-with-plugin.sh"]
restart: always
3.新增start-rabbitmq-with-plugin.sh脚本
#!/bin/bash
# 安装 wget
if ! command -v wget &> /dev/null
then
echo "wget not found, installing..."
apt-get update && apt-get install -y wget
if [ $? -ne 0 ]; then
echo "Failed to install wget"
exit 1
fi
else
echo "wget is already installed"
fi
# 创建插件目录,如果不存在的话
mkdir -p /plugins
# 下载 RabbitMQ 延迟消息插件
if [ ! -f /plugins/rabbitmq_delayed_message_exchange-3.13.0.ez ]; then
echo "Downloading rabbitmq_delayed_message_exchange plugin..."
wget -O /plugins/rabbitmq_delayed_message_exchange-3.13.0.ez \
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.13.0/rabbitmq_delayed_message_exchange-3.13.0.ez
if [ $? -ne 0 ]; then
echo "Failed to download rabbitmq_delayed_message_exchange plugin"
exit 1
fi
else
echo "Plugin already downloaded"
fi
# 修改插件文件权限
echo "Setting permissions for the plugin..."
chmod 644 /plugins/rabbitmq_delayed_message_exchange-3.13.0.ez
# 启用插件
echo "Enabling the plugin..."
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
# 启动 RabbitMQ 服务
echo "Starting RabbitMQ server..."
rabbitmq-server