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