首页 > 其他分享 >基于Docker安装RocketMQ

基于Docker安装RocketMQ

时间:2024-07-29 16:56:11浏览次数:13  
标签:Pull complete broker RocketMQ Docker 安装 docker rocketmq More

1、拉取RocketMQ镜像

代码:

docker pull apache/rocketmq

成功示例:

Using default tag: latest
latest: Pulling from apache/rocketmq
2d473b07cdd5: Pull complete
23700610a3bb: Pull complete
b58ea7c35511: Pull complete
a5224a1908d3: Pull complete
b4d9fb37957c: Pull complete
4b64a234a7c8: Pull complete
6d238122df06: Pull complete
2dddc0590d75: Pull complete
ebbdb14dda5a: Pull complete
c7afe8edd12f: Pull complete
Digest: sha256:875bc76a420e67c74607ae3809d0a39ba3a4e36e07984f17eb20ec6e4874add8
Status: Downloaded newer image for apache/rocketmq:latest
docker.io/apache/rocketmq:latest

查看获取的镜像 

docker images
REPOSITORY        TAG       IMAGE ID       CREATED       SIZE
apache/rocketmq   latest    2cee00481a8c   2 years ago   519MB
2、创namesrv服务

 创建 namesrv 数据存储路径

创建挂载目录(linux)

mkdir -p /usr/local/rocketmq/data/namesrv/logs /usr/local/rocketmq/data/namesrv/store

代码:

mkdir -p /usr/local/rocketmq/data/namesrv/logs /usr/local/rocketmq/data/namesrv/store
3、构建namesrv容器 

代码:直接将mq挂载到创建的目录,我的是win直接替换成想要的路径,没有文件夹默认创建

注意:windows 换行是 "^",linux 是 "\",使用的时候按照系统替换

docker run -d ^
--restart=always ^
--name rmqnamesrv ^
--privileged=true ^
-p 9876:9876 ^
-v /f/mount/rocketmq/data/namesrv/logs:/root/logs ^
-v /f/mount/rocketmq/data/namesrv/store:/root/store ^
-e "MAX_POSSIBLE_HEAP=100000000" ^
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" ^
apache/rocketmq ^
sh mqnamesrv

查看是否创建容器

## 查看启动的容器
docker ps 
## 查看历史容器
docker ps -a 

成功示例:

CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                                                NAMES
8fcf00571390   apache/rocketmq   "sh mqnamesrv"           6 minutes ago   Up 6 minutes   10909/tcp, 0.0.0.0:9876->9876/tcp, 10911-10912/tcp   rmqnamesrv
4、创建broker节点 
4.1 创建broker数据数据卷

创建数据卷目录,便 于进 行 数据挂载(目的同上)

 代码:(linux) 

mkdir -p /usr/local/rocketmq/data/broker/logs /usr/local/rocketmq/data/broker/store /usr/local/rocketmq/conf
4.2 创建配置文件

代码:Linux,

vi /usr/local/rocketmq/conf/broker.conf

windows 直接去目录下新建文件broker.conf

将如下代码写入新建的文件中

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 127.0.0.1
diskMaxUsedSpaceRatio=95

linux :按Esc,:wq,保存退出,即可 

4.3 构建broker容器

代码:换行如上所述,linux 系统替换成对应的挂载目录

docker run -d ^
--restart=always ^
--name rmqbroker ^
--link rmqnamesrv:namesrv ^
--privileged=true ^
-p 10911:10911 ^
-p 10912:10912 ^
-p 10909:10909 ^
-v /f/mount/rocketmq/data/broker/logs:/root/logs ^
-v /f/mount/rocketmq/data/broker/store:/root/store ^
-v /f/mount/rocketmq/conf/broker.conf:/home/rocketmq/rocketmq/conf/broker.conf ^
-e "NAMESRV_ADDR=namesrv:9876" ^
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" ^
-e "MAX_POSSIBLE_HEAP=200000000" ^
apache/rocketmq ^
sh mqbroker -c /home/rocketmq/rocketmq/conf/broker.conf

示例:

C:\Users\Administrator>docker run -d ^
More? --restart=always ^
More? --name rmqbroker ^
More? --link rmqnamesrv:namesrv ^
More? --privileged=true ^
More? -p 10911:10911 ^
More? -p 10912:10912 ^
More? -p 10909:10909 ^
More? -v /f/mount/rocketmq/data/broker/logs:/root/logs ^
More? -v /f/mount/rocketmq/data/broker/store:/root/store ^
More? -v /f/mount/rocketmq/conf/broker.conf:/home/rocketmq/rocketmq/conf/broker.conf ^
More? -e "NAMESRV_ADDR=namesrv:9876" ^
More? -e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" ^
More? -e "MAX_POSSIBLE_HEAP=200000000" ^
More? apache/rocketmq ^
More? sh mqbroker -c /home/rocketmq/rocketmq/conf/broker.conf
aadee237574a81443f443ab2f8d5bb4a8b0c649d96e5776326ccc82709720d42

 查看启动情况:

C:\Users\Administrator>docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS          PORTS                                                                      NAMES
aadee237574a   apache/rocketmq   "sh mqbroker -c /hom…"   3 minutes ago    Up 3 minutes    0.0.0.0:10909->10909/tcp, 9876/tcp, 0.0.0.0:10911-10912->10911-10912/tcp   rmqbroker
8fcf00571390   apache/rocketmq   "sh mqnamesrv"           33 minutes ago   Up 33 minutes   10909/tcp, 0.0.0.0:9876->9876/tcp, 10911-10912/tcp                         rmqnamesrv
5. 创建rocketmq-console服务
5.1 拉取rocketmq-console镜像

代码:

C:\Users\Administrator>docker pull styletang/rocketmq-console-ng
Using default tag: latest
latest: Pulling from styletang/rocketmq-console-ng
e12c678537ae: Pull complete
8d9ed335b7db: Pull complete
3318dd58ae60: Pull complete
624ba6156166: Pull complete
c7a02d193df7: Pull complete
813b62320378: Pull complete
49e2d6393f32: Pull complete
0a2b7222259b: Pull complete
478657249124: Pull complete
5f8636e9fbb7: Pull complete
Digest: sha256:96e99d10eda871640b9529b75da30fa6ca85fc15722661acb9660639e6904fc3
Status: Downloaded newer image for styletang/rocketmq-console-ng:latest
docker.io/styletang/rocketmq-console-ng:latest
C:\Users\Administrator>docker images
REPOSITORY                      TAG       IMAGE ID       CREATED       SIZE
styletang/rocketmq-console-ng   latest    7df83bb6e638   6 years ago   702MB
5.2 构建rocketmq-console容器

代码:

C:\Users\Administrator>docker run -d ^
More?  --restart=always ^
More?  --name rmqadmin ^
More?  -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1 -Dcom.rocketmq.sendMessageWithVIPChannel=false" ^
More?  -p 8081:8080 ^
More?  --ulimit nofile=1024 ^
More?  styletang/rocketmq-console-ng:latest
d593bea1fa7b5b6baa7bdfc8cd9aa862ab2bbb22846f03c9623e6945334e7352

查看容器:

C:\Users\Administrator>docker ps
CONTAINER ID   IMAGE                                  COMMAND                  CREATED              STATUS          PORTS                                                                      NAMES
7d5cc60db659   styletang/rocketmq-console-ng:latest   "sh -c 'java $JAVA_O…"   About a minute ago   Up 58 seconds   0.0.0.0:8081->8080/tcp                                                     rmqadmin
6. 启动mqnamesrv 和 mqbroker
6.1 启动mqnamesrv

代码:

C:\Users\Administrator>docker start rmqnamesrv
rmqnamesrv
6.2 启动mqbroker

代码:

C:\Users\Administrator>docker start rmqbroker
rmqbroker
7. 查看控制台信息

 访问虚拟机IP+端口号,比如:127.0.0.1:8081

8.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

# 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
9.mq 使用
使用方式
rocketmq:

注意:由于rocketmq并没有自动创建topic的功能, 所以需要进入到rockerMQ文件路径中执行
创建普通消息的topic
sh mqadmin updateTopic -n <nameserver_address> -t <topic_name> -c <cluster_name> -a +message.type=NORMAL
bin/mqadmin updatetopic -n localhost:9876 -t test-topic -c DefaultCluster
创建事务消息的topic

sh mqadmin updateTopic -n <nameserver_address> -t <topic_name> -c <cluster_name> -a +message.type=TRANSACTION
bin/mqadmin updatetopic -n localhost:9876 -t transaction-topic -c DefaultCluster -a +message.type=TRANSACTION

标签:Pull,complete,broker,RocketMQ,Docker,安装,docker,rocketmq,More
From: https://blog.csdn.net/weixin_38959316/article/details/140770028

相关文章

  • Hadoop伪分布式/分布式平台搭建教程以及安装过程中遇到部分问题的解决经验
    Hadoop伪分布式/分布式平台搭建教程声明:本搭建教程参考XMU的数据库实验室林子雨老师的搭建文档,附带了一点我们在安装时候遇到的问题和解决经验。XMU安装指导文档网址:https://dblab.xmu.edu.cn/blog/2544/目录文章目录Hadoop伪分布式/分布式平台搭建教程目录1.Linux......
  • 一款超实用的网络实时监控工具,助你轻松掌握 Docker 容器网络状态
    1.什么是check-docker-connectioncheck-docker-connection主要用于监控Docker容器的网络连接情况。它可以显示指定容器的网络连接状态,包括TCP和UDP连接的数量。用户可以通过容器ID或名称来指定要监控的容器,或者指定显示连接数最多的前N个容器。输出结果以表格......
  • PyCharm 2020 下载 安装 激活 汉化
    解压PyCharm 压缩包到当前目录下:点击此处蓝色字体下载压缩包提取码xw41鼠标右键点击PyCharmprofessional2020 选择 以管理员身份运行 :点击Next:点击Browse选择安装目录点击Next:勾选全部 点击Next:点击Install:等待安装中:选择Rebootnow......
  • T3/A40i支持Linux-5.10新内核啦,Docker、Qt、Python统统升级!
    自2021年创龙科技推出全志国产化率100%的T3/A40i工业核心板后,不到两年时间已超过800家工业客户选择创龙科技T3/A40i平台。随着客户产品的不断升级与迭代,部分“能源电力”、“工业自动化”行业客户对T3/A40i的Linux版本提出了更高要求,主要涉及Docker、Qt、Python等组件特性。秉持......
  • 再安装VMware workstation时,弹窗警告此产品安装程序不支持降级
    根据网上相关信息,总结来说就是之前卸载不完全导致的,下载一个WindowsInstallerCleanUp会有很大帮助。https://answers.microsoft.com/...以上链接为社区页面给出的回答,通过download3k网站下载我们需要的WICU(微软官方已经不提供任何下载渠道。)https://www.download3k.com/.........
  • zookeeper、kafka单机版安装 https://www.cnblogs.com/dogleftover
    zookeeper、kafka单机版安装前提已经安装了jdk1.8、zookeeper3.6.3主机名:master映射:192.168.128.129master安装zookeeper单机版#将apache-zookeeper-3.6.3-bin.tar.gz上传到服务器#解压tar-zxvfapache-zookeeper-3.6.3-bin.tar.gz#移动mv/home/apache-zookeeper-3......
  • docker安装phpadmin
    直接安装phpadmin需要有php环境,比较麻烦,总结了使用docker安装方法,并提供docker镜像。1.docker镜像见我上传的docker镜像:https://download.csdn.net/download/taotao_guiwang/895951772.安装1).加载镜像dockerload-imyphpadmin.tar2).查看镜像是否加载成功docker......
  • thinkphp: 安装fastadmin
    一,官方地址:1,官方站:https://www.fastadmin.net/2,文档地址:https://doc.fastadmin.net/docs/install.html 二,安装:1,下载:下载地址:https://www.fastadmin.net/download.html如图2,解压fastadmin安装包到服务器,并解压:liuhongdi@lhdpc:/data/site/admin/fast$u......
  • 【基础篇】Docker 架构与组件 TWO
    嗨,小伙伴们!我是小竹笋,一名热爱创作的工程师。上一篇我们聊了聊Docker的历史与发展、与虚拟机的对比以及它在行业中的应用。今天,让我们更进一步,深入探讨Docker的架构与关键组件。欢迎订阅公众号:JAVA和人工智能......
  • Docker代理备忘
    环境:vmware;debian12.6;dockerlatest目前不知道原理,直接照抄PS:看上去是docker会有默认的读取逻辑,以后有机会继续深入了解创建目录mkdir-p/etc/systemd/system/docker.service.dvim/etc/systemd/system/docker.service.d/proxy.conf设置文件内容,里面填写对应的ip地......