Docker搭建RocketMQ问题及解决方案

3 篇文章 0 订阅
2 篇文章 0 订阅

本文为Docker搭建RocketMQ问题及解决方案

转载请注明:http://blog.csdn.net/sinat_28434649/article/details/79291988

1、环境

OS:Linux
Docker:1.6.2
RocketMQ:4.2
搭建参考 rocketmq-docker,请下载该工程

1.2、构建mqnamesrv镜像

下载rocketmq-docker

#构架镜像
sh docker_build.sh

构建失败

1.3、修改mqnamesrv\Dockerfile内容

查看Dockerfile内容

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Start from a Java image.
FROM java:8

# Rocketmq version
ENV ROCKETMQ_VERSION 4.0.0-incubating

# Rocketmq home
ENV ROCKETMQ_HOME  /opt/rocketmq-${ROCKETMQ_VERSION}



WORKDIR  ${ROCKETMQ_HOME}

RUN mkdir -p \
		/opt/logs \
	    /opt/store

RUN curl https://dist.apache.org/repos/dist/release/incubator/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip \
          && unzip rocketmq.zip \
          && mv apache-rocketmq-all/* . \
          && rmdir apache-rocketmq-all  \
          && rm rocketmq.zip


RUN chmod +x bin/mqbroker

CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT=" -Duser.home=/opt" && sh mqbroker


EXPOSE 10909 10911
VOLUME /opt/logs \
		/opt/store

发现以上链接已失效。上官网查找下载链接更新Dockerfile文件

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


# Start from a Java image.
FROM java:8


# Rocketmq version
ENV ROCKETMQ_VERSION 4.2.0


# Rocketmq home
ENV ROCKETMQ_HOME  /opt/rocketmq-${ROCKETMQ_VERSION}


WORKDIR  ${ROCKETMQ_HOME}


RUN mkdir -p \
		/opt/logs \
		/opt/store


RUN curl http://mirror.bit.edu.cn/apache/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip \
          && unzip rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip \
          && rm rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip




RUN chmod +x bin/mqnamesrv


CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT=" -Duser.home=/opt"  && sh mqnamesrv -c /opt/rocketmq-4.2.0/conf/broker.conf




EXPOSE 9876
VOLUME /opt/logs \
		/opt/store
加载默认配置文件,实际使用是需修改配置文件。

1.4、再次构建mqnamesrv镜像

#构架镜像
sh docker_build.sh

1.5、创建容器

#创建容器
docker run -d -p 9876:9876 --name rmqnamesrv -e "JAVA_OPT_EXT=-server -Xms128m -Xmx256m -Xmn128m" apache/incubator-rocketmq-namesrv:4.2.0-incubating

2.1、构建broker镜像

同理修改mqnamesrv\Dockerfile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


# Start from a Java image.
FROM java:8


# Rocketmq version
ENV ROCKETMQ_VERSION 4.2.0


# Rocketmq home
ENV ROCKETMQ_HOME  /opt/rocketmq-${ROCKETMQ_VERSION}






WORKDIR  ${ROCKETMQ_HOME}


RUN mkdir -p \
		/opt/logs \
	    /opt/store


RUN curl http://mirror.bit.edu.cn/apache/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip \
          && unzip rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip \
          && rm rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip




RUN chmod +x bin/mqbroker


CMD cd ${ROCKETMQ_HOME}/bin && export && export JAVA_OPT=" -Duser.home=/opt"  && sh mqbroker -c /opt/rocketmq-4.2.0/conf/broker.conf





EXPOSE 10909 10911
VOLUME /opt/logs \
		/opt/store

默认加载配置文件,实际使用是需修改配置文件。

#构架镜像
sh docker_build.sh

2.2、创建容器

docker run -d -p 10911:10911 -p 10909:10909 --name rmqbroker --link rmqnamesrv:rmqnamesrv -e "NAMESRV_ADDR=rmqnamesrv:9876"  -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m"  apache/incubator-rocketmq-broker:4.2.0-incubating


3、测试RocketMQ

root> docker exec -it rmqnamesrv /bin/bash
ERRO[0000] Unable to connect to local syslog daemon     
root@84b097b311e9:/opt/rocketmq-4.2.0# cd /opt/rocketmq-4.2.0/
root@84b097b311e9:/opt/rocketmq-4.2.0# export NAMESRV_ADDR=localhost:9876
root@84b097b311e9:/opt/rocketmq-4.2.0# sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
....
SendResult [sendStatus=SEND_OK, msgId=AC11004101216E0BE85827526C4A0263, offsetMsgId=AC11004200002A9F000000000002BE44, messageQueue=MessageQueue [topic=TopicTest, brokerName=a2e2cadee871, queueId=0], queueOffset=250]
SendResult [sendStatus=SEND_OK, msgId=AC11004101216E0BE85827526C500264, offsetMsgId=AC11004200002A9F000000000002BEF8, messageQueue=MessageQueue [topic=TopicTest, brokerName=a2e2cadee871, queueId=1], queueOffset=250]
....

生产消息成功

root>sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
....
ConsumeMessageThread_18 Receive New Messages: [MessageExt [queueId=1, storeSize=179, queueOffset=100, sysFlag=0, bornTimestamp=1518102906647, bornHost=/172.17.0.65:50605, storeTimestamp=1518102906650, storeHost=/172.17.0.66:10911, msgId=AC11004200002A9F0000000000011970, commitLogOffset=72048, bodyCRC=1703501626, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=252, CONSUME_START_TIME=1518103025749, UNIQ_KEY=AC11004101216E0BE85827525317000C, WAIT=true, TAGS=TagA}, body=17]]] 
ConsumeMessageThread_14 Receive New Messages: [MessageExt [queueId=1, storeSize=180, queueOffset=92, sysFlag=0, bornTimestamp=1518100775617, bornHost=/172.17.0.65:48328, storeTimestamp=1518100775618, storeHost=/172.17.0.66:10911, msgId=AC11004200002A9F0000000000010306, commitLogOffset=66310, bodyCRC=738600450, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=252, CONSUME_START_TIME=1518103025736, UNIQ_KEY=AC11004100566E0BE8582731CEC10171, WAIT=true, TAGS=TagA}, body=18]]] 
ConsumeMessageThread_16 Receive New Messages: [MessageExt [queueId=1, storeSize=180, queueOffset=90, sysFlag=0, bornTimestamp=1518100775585, bornHost=/172.17.0.65:48328, storeTimestamp=1518100775587, storeHost=/172.17.0.66:10911, msgId=AC11004200002A9F000000000000FD66, commitLogOffset=64870, bodyCRC=584953392, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=252, CONSUME_START_TIME=1518103025735, UNIQ_KEY=AC11004100566E0BE8582731CEA10169, WAIT=true, TAGS=TagA}, body=18]]] 
....

消费消息成功


4、问题总结

1】构建失败,查看一下官网看一下连接是否修改了;查看最新包,文件夹目录是否调整

2】out of memory问题,修改一下容器启动参数即可。

3】在docker下运行RocketMQ时,通过java客户端远程调用,namesrv返回的是docker容器的地址,java客户端无法访问到。

可以通过配置brokerIP1 = 实际ip 解决。(本机ip地址,默认系统自动识别,但是某些多网卡机器会存在识别错误的情况,这种情况下可以人工配置 解决。

具体需要加载配置文件,需要在构建的时候 追加 -c /opt/rocketmq-4.2.0/conf/broker.conf,再进入容器修改配置文件)

4】CODE: 1  DESC: java.lang.NullPointerException, org.apache.rocketmq.common.message.MessageExt.socketAddress2ByteBuffer(MessageExt.java:69)

尝试关闭再开启防火墙(PS:我的是群晖的机器,每次都要重启一下防火墙,原因未知)



5、结束语

Docker下按照官方文档搭建RocketMQ,主要遇到的问题是,原本的构建脚本不能用了,研究一下Dockerfile,按目前的版本修改即可。遇到out of memory,修改JVM启动参数即可。


6、参考文档:

http://rocketmq.apache.org/docs/quick-start/

https://github.com/apache/rocketmq-externals/tree/master/rocketmq-docker

http://blog.csdn.net/u013256816/article/details/54743551



  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要在Docker搭建RocketMQ,您可以按照以下步骤操作: 1. 首先,确保您已经安装了DockerDocker Compose。 2. 在您的项目目录中创建一个名为`docker-compose.yml`的文件,并将以下内容复制到文件中: ```yaml version: '3' services: namesrv: image: rocketmqinc/rocketmq:4.8.0 container_name: rocketmq-namesrv ports: - 9876:9876 volumes: - ./data/namesrv/logs:/root/logs command: sh mqnamesrv broker: image: rocketmqinc/rocketmq:4.8.0 container_name: rocketmq-broker ports: - 10909:10909 - 10911:10911 environment: - NAMESRV_ADDR=namesrv:9876 volumes: - ./data/broker/logs:/root/logs - ./data/broker/store:/root/store command: sh mqbroker -n namesrv:9876 ``` 3. 创建一个名为`data/namesrv/logs`的文件夹用于存储Namesrv的日志。 4. 创建一个名为`data/broker/logs`和`data/broker/store`的文件夹,用于存储Broker的日志和存储文件。 5. 打开终端,进入到包含`docker-compose.yml`文件的项目目录,并运行以下命令启动RocketMQ: ```bash docker-compose up -d ``` 6. 等待一段时间,RocketMQ将会在Docker容器中启动。您可以使用以下命令查看容器的运行状态: ```bash docker ps ``` 7. 确保Namesrv和Broker容器都处于运行状态后,您可以使用RocketMQ提供的客户端工具进行操作。 这样,您就成功地在Docker搭建RocketMQ。记得在使用完成后,使用以下命令停止并删除容器: ```bash docker-compose down ``` 希望对您有所帮助!如果有任何疑问,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值