使用docker-compose部署RocketMQ5.0
使用docker-compose部署rocketmq5.0。文中会介绍docker-compose版本以及需要注意的项。
·
简介:
使用docker-compose部署rocketmq5.0。文中会介绍docker-compose版本以及需要注意的项
第一步:进入hub.docker.com搜索rocketmq
我们选择第一个,因为第一个是7个月前更新的,(我看有很多博客使用的依旧是最下面的那种版本,但是现在的一些配置已经都不一样了,导致很多东西不能用)
第二步:下载docker-compose并赋予权限
https://get.daocloud.io/#install-compose
# get.daocloud.io是国内链接,因此可以高速安装
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.12.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
提示:v2.12.2是版本号,可以自己更换
chmod +x /usr/local/bin/docker-compose #授权,如果没有赋予权限,下一步是查不到的
docker-compose version # docker-compose -v 都可以查看版本
执行刚刚复制的命令下载rocketmq最新版
docker pull apache/rocketmq:latest
第三步:进入服务器建立需要映射的文件夹和文件
提示:推荐在/usr/local中建立,因为linux中每个文件夹都有其用意,我们应该遵守规则。
1、建立文件夹
mkdir rocketmq
mkdir rocketmq/logs
mkdir rocketmq/data
mkdir rocketmq/conf
不小心建错使用下面命令删除
rm -rf 文件夹名称
2、在conf文件夹下建立broker.conf文件
vim broker.conf
broker.conf的内容可以从这里复制:
https://github.com/apache/rocketmq/blob/master/distribution/conf/broker.conf
# 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.
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 服务器ip地址
说明:我们之所以要建立broker.conf文件,是因为我们需要通过这个文件把RocketMQ管理起来,尽管我们可以暂时什么都不做
3、在rocketmq文件夹中建立docker-compose.yml文件
vim docker-compose.yml
#version: '3.8'
services:
nameserver:
image: apache/rocketmq:5.1.0
container_name: rmqnamesrv
ports:
- 9876:9876
restart: always
volumes:
- /usr/local/docker/rocketmq/logs:/home/rocketmq/logs
environment:
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -Xms256M -Xmx256M -Xmn128m"
command: ["sh","mqnamesrv"]
broker:
image: apache/rocketmq:5.1.0
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
restart: always
volumes:
- /usr/local/docker/rocketmq/logs:/root/logs
- /usr/local/docker/rocketmq/store:/root/store
- /usr/local/docker/rocketmq/conf/broker.conf:/home/rocketmq/broker.conf
links:
- nameserver:namesrv
depends_on:
- 'nameserver'
environment:
NAMESRV_ADDR: nameserver:9876
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -Xms256M -Xmx256M -Xmn128m"
command: ["sh","mqbroker","-c","/home/rocketmq/broker.conf","autoCreateTopicEnable=true"]
rmqdashboard:
image: apacherocketmq/rocketmq-dashboard:latest
container_name: rocketmq-dashboard
ports:
- 8082:8080
restart: always
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=nameserver:9876"
注意:volumes参数的映射规则是," : "冒号前面是宿主机的文件夹和文件路径,冒号后面是容器内的路径。在配置broker的volumes时,容器内的路径一定要用root开头,否则会导致broker启动的时候一直退出,查看日志也没有任何信息,只能在docker-compose up的时候看见:rmqbroker exited with code 253
说明:
apacherocketmq/rocketmq-dashboard:latest
这个镜像是控制台的镜像,在docker-compose中配置好之后,启动时会自动下载(其实所有镜像配置完成后在启动时都会校验,没有则自动下载)
启动
docker-compose up -d # “ -d ” 指后台运行,想看启动时的日志可以不用加
成功
结尾
附加几个docker-compose常用的命令,如果配置有问题,方便删除重新构建
验证编写的docker-compose.yml 是否正确
docker-compose build
或者
docker-compose config -g
停止docker-compose运行的镜像
docker-compose stop
停止并删除docker-compose运行的镜像
docker-compose down
删除docker-compose发布的容器
docker-compose rm
在代码中发送消息时遇到的问题:
一、org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
该问题的解决方式是在broker.conf文件中添加一行参数:
brokerIP1 = 服务器IP
完事重新启动broker即可。
-
发送成功
-
控制台显示
-
消费成功
更多推荐
已为社区贡献2条内容
所有评论(0)