下载rockermq包:
https://rocketmq.apache.org/zh/download/
source开源和binary二进制安装
开始编写rmqnamesrv的dockerfile
FROM java:openjdk-8u111-alpine
ENV ROCKETMQ_VERSION 5.1.3
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
WORKDIR ${ROCKETMQ_HOME}
RUN set -x && rm -f /etc/localtime && ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
ADD bin ${ROCKETMQ_HOME}/bin
ADD conf ${ROCKETMQ_HOME}/conf
ADD lib ${ROCKETMQ_HOME}/lib
RUN mkdir -p /opt/logs /opt/store
VOLUME /opt/logs /opt/store
EXPOSE 9876
RUN chmod +x /opt/rocketmq-5.1.3/bin/mqnamesrv
CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT="-Duser.home=/opt -Xms512M -Xmx512M -Xmn128m " && sh mqnamesrv
开始编写rmqbroker的dockerfile
FROM java:openjdk-8u111-alpine
ENV ROCKETMQ_VERSION 5.1.3
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
WORKDIR ${ROCKETMQ_HOME}
RUN set -x && rm -f /etc/localtime && ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
ADD bin ${ROCKETMQ_HOME}/bin
ADD conf ${ROCKETMQ_HOME}/conf
ADD lib ${ROCKETMQ_HOME}/lib
RUN mkdir -p /opt/logs /opt/store
VOLUME /opt/logs /opt/store
EXPOSE 10909 10911
RUN chmod +x bin/mqbroker
CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT="-Duser.home=/opt -server -Xms512M -Xmx512M -Xmn128m" && sh mqbroker -n ${NAMESRV_ADDR} -c ../conf/broker.conf
生成镜像
docker build -f 指定你编写的dockerfile文件 -t 镜像name:版本 .
查看我实验生成的images
命令启动rockermq服务
这里NAMESRV_ADDR=1.1.1.1:9876是需要指定你安装的rmqnamesrv的ip+端口,-v挂载的日志以及对于的配置。
docker run -d -p 9876:9876 --name rmqnamesrv --restart=always rocketmq-namesrv:5.1.3
docker run -d -p 10911:10911 -p 10909:10909 --name rmqbroker --restart=always -e "NAMESRV_ADDR=1.1.1.1:9876" -v /opt/rocketmq/logs:/opt/logs -v /opt/rocketmq/store:/opt/store -v /home/conf/brocker.conf:/opt/rocketmq-5.1.3/conf/brocker.conf --link rmqnamesrv
对应brocker的配置文件:
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1=1.1.1.1 #配置服务器ip
autoCreateTopicEnable=true
问题点:
如果容器启动,查看日志发现是killed的情况,说明你的运行空间不够!要限制服务的内存使用! 实验是加了8g内存去验证的
说明我们JAVA_OPTS 指定没有生效!
解决方案启动容器限制一下:
-e JAVA_OPT_EXT = -server -Xms128m -Xmx128m -Xmn128m
docker-compose启动文章来源:https://www.toymoban.com/news/detail-682321.html
rmqnamesrv:
restart: always
image: rmqnamesrv:5.1.3
container_name: rmqnamesrv
ports:
- 9876:9876
environment:
JAVA_OPT_NXT: "-Duser.home=/opt -Xms512M -Xmx512M -Xmn128m"
rmqbroker:
restart: always
image: rmqbroker:5.1.3
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
volumes:
- /home/rocketmq/logs:/opt/logs
- /home/rocketmq/store:/opt/store
- /home/rocketmq/conf/broker.conf:/opt/rocketmq-5.1.3/conf/broker.conf
environment:
NAMESRV_ADDR: "rmqnamesrv:9876"
JAVA_OPT_EXT: "-Duser.home=/opt -server -Xms512M -Xmx512M -Xmn128m"
depends_on:
- rmqnamesrv
没有限制前:
限制后:
文章来源地址https://www.toymoban.com/news/detail-682321.html
到了这里,关于RocketMQ-dockefile制作镜像过程(一学就废)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!