xiaoming728

xiaoming728

Docker环境搭建单机版RocketMQ

2023-12-11
Docker环境搭建单机版RocketMQ

1、下载rocketmq-docker源码

git clone https://github.com/apache/rocketmq-docker.git

2、编译RocketMQ镜像

cd image-build
sh build-image.sh RMQ-VERSION BASE-IMAGE

注意: RMQ-VERSION:表示编译的版本点击 这里获取。 BASE-IMAGE:取值 [centos, alpine].

举个栗子: sh build-image.sh 4.8.0 alpine

3、生成RocketMQ运行目录

sh stage.sh RMQ-VERSION

注意:RMQ-VERSION是RocketMQ镜像的标签。执行完上述shell脚本(例如sh stage.sh 4.8.0)后,它将生成一个stage目录(./stages/4.8.0)。例如RMQ版本是4.8.0,则用户可以在目录下启动RMQ容器。

4、安装RocketMQ容器

使用脚本安装

# 1、创建目录
mkdir -p /home/docker/rocketmq
# 2、copy初始化配置
cp -r ./stages/4.8.0/data play-docker.sh /home/docker/rocketmq
# 3、安装容器
cd /home/docker/rocketmq 
sh play-docker.sh alpine

使用docker命令安装

1、centos环境安装

如果镜像编译的是centos环境,使用一下安装命令

# Start nameserver
docker run -d --name rmqnamesrv \
 -v /home/docker/rocketmq/data/namesrv/logs:/home/rocketmq/logs \
 -p 9876:9876 \
 apacherocketmq/rocketmq:4.8.0 sh mqnamesrv
 
 # Start Broker
docker run -d --name rmqbroker \
 -v /home/docker/rocketmq/broker/logs:/home/rocketmq/logs \
 -v /home/docker/rocketmq/data/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
 --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" \
 -p 10909:10909 -p 10911:10911 -p 10912:10912 \
 apacherocketmq/rocketmq:4.8.0 \
 sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf

2、alpine环境安装

如果镜像编译的是alpine环境,使用一下安装命令

# Start nameserver
docker run -d --name rmqnamesrv \
 -v /home/docker/rocketmq/data/namesrv/logs:/home/rocketmq/logs \
 -p 9876:9876 \
 apacherocketmq/rocketmq:4.8.0-alpine sh mqnamesrv

# Start Broker
docker run -d --name rmqbroker \
 -v /home/docker/rocketmq/data/broker/logs:/home/rocketmq/logs \
 -v /home/docker/rocketmq/data/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
 --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" \
 -p 10909:10909 -p 10911:10911 -p 10912:10912 \
 apacherocketmq/rocketmq:4.8.0-alpine \
 sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf

5、安装RocketMQ-Console-NG图形控制台

1、下载镜像

docker pull styletang/rocketmq-console-ng

2、安装镜像

docker run -d -p 8080:8080 --name rocketmq-console-ng \
-v /home/docker/rocketmq/tmp:/tmp \
--link rmqnamesrv:namesrv \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
styletang/rocketmq-console-ng