当前位置: 代码网 > 服务器>服务器>云虚拟主机 > Docker部署RocketMQ的实现示例

Docker部署RocketMQ的实现示例

2024年11月03日 云虚拟主机 我要评论
1.namesrv1.1 拉取rocketmq镜像docker pull apache/rocketmq:4.9.41.2创建nameserver数据存储目录rocketmq 分为nameserver

1.namesrv

1.1 拉取rocketmq镜像

docker pull apache/rocketmq:4.9.4

1.2  创建nameserver数据存储目录

rocketmq 分为nameserver和broker两部分,在启动时应该先启动nameserver,因此我们现在先创建nameserver的日志和数据存放目录。这个目录可由我们自己定义路径,这里我将其放到data路径

mkdir -p /app/rocketmq/logs /app/rocketmq/store

1.3 构建namesrv容器并启动

我们已经创建好了nameserver的日志和数据的存放路径,此时我们只需要挂在日志和数据路径,执行以下命令启动nameserver即可

docker run -d -p 9876:9876 --restart=always \
  -v /app/rocketmq/namesrv/logs:/home/rocketmq/logs \
  -v /app/rocketmq/namesrv/store:/home/rocketmq/store \
  --name mqnamesrv \
  --network rocketmq \
  -e"java_opt_ext=-server -xms512m -xmx512m -xmn512m" \
  apache/rocketmq:4.9.4 \
  sh mqnamesrv

2.broker

2.1 创建broker数据存储路径

在操作这步之前,我们已经将nameserver启动成功,则接下来我们将要为broker创建数据挂载目录和配置文件,以确保broker能够成功启动。

mkdir -p /app/rocketmq/broker/logs  /app/rocketmq/broker/store /app/rocketmq/broker/conf

说明:logs:是broker的日志目录,store:是broker的数据目录(该目录需求所有读写权限),conf是broker的配置信息目录

2.2 创建broker配置文件

我们刚刚已经创建了broker配置目录(/data/rocketmqbroker/conf),现在我们要在改配置目录下增加一个broker的配置文件,命名叫broker.conf

cd /app/rocketmq/broker/conf
vi broker.conf

注意:将一下信息复制到broker.conf文件中,请注意修改brokerip1,改为您服务器的ip地址!注意修改namesrvaddr,改为您nameserver的ip地址!

# 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
# broker 名字,注意此处不同的配置文件填写的不一样,如果在 broker-a.properties 使用: broker-a,
# 在 broker-b.properties 使用: broker-b
brokername=broker-a
# 0 表示 master,> 0 表示 slave
brokerid=0
# nameserver地址,分号分割
namesrvaddr=192.168.18.200: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
#producer.setvipchannelenabled=false
brokerip1=192.168.18.200

# 在发送消息时,自动创建服务器不存在的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

2.3 构建broker容器并启动

docker run -d -p 10911:10911 -p 10909:10909 \
-v /app/rocketmq/broker/logs:/home/rocketmq/logs \
-v /app/rocketmq/broker/store:/home/rocketmq/store \
-v /app/rocketmq/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf \
--name rmqbroker \
-e "namesrv_addr=mqnamesrv:9876" \
 apache/rocketmq:4.9.4 \
sh mqbroker -n mqnamesrv:9876 \
-c  /home/rocketmq/rocketmq-4.9.4/conf/broker.conf autocreatetopicenable=true

3.rocketmq-console可视化界面

3.1 拉取rocketmq-console镜像

docker pull styletang/rocketmq-console-ng

3.2 构建rocketmq-console容器并启动

docker run -d --restart=always --name rocketmq-admin -e "java_opts=-drocketmq.namesrv.addr=mqnamesrv:9876 -dcom.rocketmqsendmessagewithvipchannel=false"  -p 18080 :8080  styletang/rocketmq-console-ng

注意:将一下信息drocketmq.namesrv.addr后面的ip地址改为您的nameserver ip地址!

到此这篇关于docker部署rocketmq的实现示例的文章就介绍到这了,更多相关docker部署rocketmq内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com