docker、docker-compose部署rocketmq4.7.0
一、源码部署
1.版本历史
- 4.7.0
- server-4.6.1 , broker-4.6.1
- server-4.5.2 , broker-4.5.2
- server-4.5.1 , broker-4.5.1
- server-4.5.0 , broker-4.5.0
2.本镜像使用的是官方的
https://github.com/apache/rocketmq-docker
官方地址,有问题找官方
rocketmq
rocketmq Version 4.5.1, 4.5.2 ,4.6.1 , 4.7.0
3.docker-rocketmq 镜像
4.7.0 版本镜像 将 不在根据base镜像生成 server,broker 镜像,统一使用 base 镜像,两者区别只是调用的 启动文件不同
4.源码部署rocketmq
#案例 版本 4.7.0
git clone https://github.com/foxiswho/docker-rocketmq.git
cd docker-rocketmq/rmq
chmod +x start.sh
./start.sh
#访问浏览器
localhost:8180
注意 如果你的微服务或者项目在开发的时候没有放入docker中或者与rocketmq容器不能直接用IP访问, 那么请把broker.conf中的 #brokerIP1=192.168.0.253 前面#号去掉,并且把后面的IP地址改成你的rocketmq容器宿主机IP地址, 否则报 com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <172.0.0.120:10909> failed
配置文件 在 rmq/rmq/brokerconf 目录下
二、rocketmq 4.7.0 新版 启动
(一)server
1.server 无日志目录映射
docker run --name rmqnamesrv \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
-p 9876:9876 \
-d foxiswho/rocketmq:4.7.0 \
sh mqnamesrv
2.server 有日志目录映射
docker run --name rmqnamesrv \
-v $(pwd)/logs:/home/rocketmq/logs \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
-p 9876:9876 \
-d foxiswho/rocketmq:4.7.0 \
sh mqnamesrv
(二)broker
1.broker 无目录映射
docker run --name rmqnamesrv \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
-p 10909:10909 -p 10911:10911 -p 10912:10912 \
-d foxiswho/rocketmq:4.7.0 \
sh mqbroker -c /home/rocketmq/conf/broker.conf
2.broker 目录映射
docker run --name rmqbroker \
-v $(pwd)/logs:/home/rocketmq/logs \
-v $(pwd)/store:/home/rocketmq/store \
-v $(pwd)/conf:/home/rocketmq/conf \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
-p 10909:10909 -p 10911:10911 -p 10912:10912 \
-d foxiswho/rocketmq:4.7.0 \
sh mqbroker -c /home/rocketmq/conf/broker.conf
三、rocketmq 4.7.0 以前 旧版启动
1.server
docker run --name rmqserver \
-p 9876:9876 \
-d foxiswho/rocketmq:server
2.broker
docker run --name rmqbroker \
-p 10911:10911 -p 10909:10909 \
--link rmqserver:rmqserver \
-e "NAMESRV_ADDR=rmqserver:9876" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m -Duser.home=/opt" \
-d foxiswho/rocketmq:broker
#(容器内)broker 配置文件位置
/etc/rocketmq/broker.conf
2.1.如果要使用自己的配置文件
#如果要使用自己的配置文件,那么先把你以前创建好的 容器 rmqbroker 先删除,然后再执行如下:请全部复制到shell中执行
docker run --name rmqbroker \
--link rmqserver:rmqserver \
-p 10909:10909 -p 10911:10911 \
-e "NAMESRV_ADDR=rmqserver:9876" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m -Duser.home=/opt" \
-v /home/local/rmq/conf/broker.conf:/etc/rocketmq/broker.conf \
-d foxiswho/rocketmq:broker
#/home/local/rmq/conf/broker.conf 为我的本地配置文件目录,把他替换成你自己的
如果你的微服务没有使用docker,那么需要把/etc/rocketmq/broker.conf 配置文件中的 brokerIP1=192.168.0.253 这个启用,
IP 地址填写 你docker 所在 宿主机的IP ,否则报错。broker.conf 内容如下:文章来源:https://www.toymoban.com/news/detail-599579.html
# 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.
# broker.conf
# 所属集群名字
brokerClusterName=DefaultCluster
# broker 名字,注意此处不同的配置文件填写的不一样,如果在 broker-a.properties 使用: broker-a,
# 在 broker-b.properties 使用: broker-b
brokerName=broker-a
# 0 表示 Master,> 0 表示 Slave
brokerId=0
# nameServer地址,分号分割
# namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
# 启动IP,如果 docker 报 com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <192.168.0.120:10909> failed
# 解决方式1 加上一句 producer.setVipChannelEnabled(false);,解决方式2 brokerIP1 设置宿主机IP,不要使用docker 内部IP
#brokerIP1=192.168.0.253
# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 !!!这里仔细看是 false,false,false
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认凌晨4点
deleteWhen=04
# 文件保留时间,默认48小时
fileReservedTime=120
# commitLog 每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
# destroyMapedFileIntervalForcibly=120000
# redeleteHangedFileInterval=120000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 存储路径
# storePathRootDir=/home/ztztdata/rocketmq-all-4.1.0-incubating/store
# commitLog 存储路径
# storePathCommitLog=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/commitlog
# 消费队列存储
# storePathConsumeQueue=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/consumequeue
# 消息索引存储路径
# storePathIndex=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/index
# checkpoint 文件存储路径
# storeCheckpoint=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/checkpoint
# abort 文件存储路径
# abortFile=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/abort
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker 的角色
# - ASYNC_MASTER 异步复制Master
# - SYNC_MASTER 同步双写Master
# - SLAVE
brokerRole=ASYNC_MASTER
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128
3.console
#来自 https://hub.docker.com/r/styletang/rocketmq-console-ng
docker run --name rmqconsole -p 8180:8080 \
--link rmqserver:rmqserver \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=rmqserver:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-d styletang/rocketmq-console-ng
#浏览器访问
localhost:8180
四、docker-compose部署rocketmq4.5.2
#新建rocketmq目录
mkdir -p /home/local/rocketmq1/data/{brokerconf,store,logs}
#将 三、rocketmq4.7.0以前旧版启动中的 broker.conf 的内容保存为broker.conf
cd /home/local/rocketmq1/data/brokerconf
vi broker.conf
#新建下面的docker-compose.yml文件和保存内容,然后启动部署
cd /home/local/rocketmq1
vi docker-compose.yml
#启动
docker-compose up -d
#查看是否启动成功
docker-compose ps -a
#防火墙开放端口
firewall-cmd --zone=public --add-port={8180,9876,10909,10911}/tcp --permanent
firewall-cmd --reload
#访问
localhost:8180
docker-compose.yml文章来源地址https://www.toymoban.com/news/detail-599579.html
version: '3.5'
# 在 $pwd/rocketmq1/docker-compose.yml进行运行:
# 默认的docker-compose.yml运行:docker compose up -d
# 指定的docker-compose.yml运行:docker compose up -d -f xxx-compose.yml
# 查看容器:docker compose ps -a
# 停止/启动service:docker compose stop/start/restart
# 删除service[同时会删除掉network和volume]:docker compose down [-f xxx-compose.yml]
# 查看日志:docker-compose logs <容器id或名称>
# 进入到某个service:docker compose exec <容器id或名称> sh
services:
rmqserver1:
image: foxiswho/rocketmq:server
container_name: rmqserver1
ports:
- 9876:9876
volumes:
- ./data/logs:/opt/logs
- ./data/store:/opt/store
environment:
JAVA_OPT_EXT: "-Xms128M -Xmx128M -Xmn32m"
restart: 'no'
networks:
rmq1:
aliases:
- rmqserver1
rmqbroker1:
image: foxiswho/rocketmq:broker
container_name: rmqbroker1
ports:
- 10909:10909
- 10911:10911
volumes:
- ./data/logs:/opt/logs
- ./data/store:/opt/store
- ./data/brokerconf/broker.conf:/etc/rocketmq/broker.conf
environment:
NAMESRV_ADDR: "rmqserver1:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: mqbroker -c /etc/rocketmq/broker.conf
depends_on:
- rmqserver1
restart: 'no'
networks:
rmq1:
aliases:
- rmqbroker1
rmqconsole1:
image: styletang/rocketmq-console-ng
container_name: rmqconsole1
ports:
- 8180:8080
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqserver1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
depends_on:
- rmqserver1
restart: 'no'
networks:
rmq1:
aliases:
- rmqconsole1
#网络。networks跟services节点是同一级
networks:
rmq1:
name: rmq1
driver: bridge
到了这里,关于docker、docker-compose部署rocketmq4.7.0的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!