RocketMQ的部署主要是broker和namesrv,broker是MQ的消息中转角色,负责存储消息,转发消息,一般称为Server。在 JMS 规范中称为 Provider。namesrv是一个几乎无状态节点,接受broker的Topic信息注册,为 producer 和 consumer 提供路由信息。。
1、namesrv镜像
1.1、创建Dockerfile文件
#当前用户
who
xusg pts/0 2018-02-02 17:33 (192.168.56.1)
#当前目录
pwd
/home/xusg/docker/rocketmq/namesrv
#创建Dockerfile文件
touch Dockerfile
#Dockerfile文件内容
#RocketMQ以来Java环境,因此基于Java镜像进行构建
#修改启动参数-Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m为-Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m,虚拟机内存较小
#9876:消息监听端口
FROM java:8
ENV ROCKETMQ_VERSION 4.2.0
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
ENV JAVA_OPT " -Duser.home=/opt"
WORKDIR ${ROCKETMQ_HOME}
RUN mkdir -p /opt/logs /opt/store
RUN curl https://dist.apache.org/repos/dist/release/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip \
&& unzip rocketmq.zip \
&& rm rocketmq.zip \
&& cd ${ROCKETMQ_HOME}/bin \
&& sed -i 's#-Xms[0-9]\+[gm]#-Xms256m#' runserver.sh \
&& sed -i 's#-Xmx[0-9]\+[gm]#-Xmx256m#' runserver.sh \
&& sed -i 's#-Xmn[0-9]\+[gm]#-Xmn128m#' runserver.sh \
&& sed -i 's#-XX:MetaspaceSize=[0-9]\+[gm]#-XX:MetaspaceSize=64m#' runserver.sh \
&& sed -i 's#-XX:MaxMetaspaceSize=[0-9]\+[gm]#-XX:MaxMetaspaceSize=128m#' runserver.sh \
&& chmod +x ./mqnamesrv
CMD cd ${ROCKETMQ_HOME}/bin && sh mqnamesrv
EXPOSE 9876
VOLUME ["/opt/logs", "/opt/store"]
1.2、构建namesrv镜像
#进入Dockerfile文件所在目录
cd /home/xusg/docker/rocketmq/namesrv
#构建镜像
sudo docker build -t study/rocketmq-namesrv:4.2.0 .
2.3、查看namesrv镜像
#查看docker镜像列表
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
study/rocketmq-namesrv 4.2.0 b2b9f7c76c31 58 seconds ago 653 MB
java 8 d23bdf5b1b1b 12 months ago 643 MB
#查看study/rocketmq-namesrv镜像信息
sudo docker inspect study/rocketmq-namesrv:4.2.0
2、broker镜像
2.1、创建Dockerfile文件
#当前用户
who
xusg pts/0 2018-02-02 17:33 (192.168.56.1)
#当前目录
pwd
/home/xusg/docker/rocketmq/broker
#创建Dockerfile文件
touch Dockerfile
#Dockerfile文件内容
#RocketMQ以来Java环境,因此基于Java镜像进行构建
#修改启动参数-Xms8g -Xmx8g -Xmn4g为-Xms256m -Xmx256m -Xmn128m,虚拟机内存较小
#10911:消息监听端口
#10912:主从同步端口
FROM java:8
ENV ROCKETMQ_VERSION 4.2.0
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
ENV JAVA_OPT " -Duser.home=/opt"
WORKDIR ${ROCKETMQ_HOME}
RUN mkdir -p /opt/logs /opt/store
RUN curl https://dist.apache.org/repos/dist/release/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip \
&& unzip rocketmq.zip \
&& rm rocketmq.zip \
&& cd ${ROCKETMQ_HOME}/bin \
&& sed -i 's#-Xms[0-9]\+[gm]#-Xms256m#' runbroker.sh \
&& sed -i 's#-Xmx[0-9]\+[gm]#-Xmx256m#' runbroker.sh \
&& sed -i 's#-Xmn[0-9]\+[gm]#-Xmn128m#' runbroker.sh \
&& chmod +x ./mqbroker
EXPOSE 10909 10911 10912
VOLUME ["/opt/logs", "/opt/store"]
CMD cd ${ROCKETMQ_HOME}/bin && sh mqbroker
2.2、构建broker镜像
#进入Dockerfile文件所在目录
cd /home/xusg/docker/rocketmq/broker
#构建镜像
sudo docker build -t study/rocketmq-broker:4.2.0 .
2.3、查看broker镜像
#查看docker镜像列表
sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
study/rocketmq-namesrv 4.2.0 b2b9f7c76c31 58 seconds ago 653 MB
study/rocketmq-broker 4.2.0 fcd6975639b1 36 seconds ago 653 MB
java 8 d23bdf5b1b1b 12 months ago 643 MB
#查看study/rocketmq-broker镜像信息
sudo docker inspect study/rocketmq-broker:4.2.0