创建NameServer挂载文件夹
1
| mkdir /usr/local/rocketmq/nameserver/{logs,bin} -p
|
设置权限:如果不设置会导致NameServer容器内部无法写日志文件
1 2
| chmod 777 -R /usr/local/rocketmq/nameserver/*
|
创建挂载文件
NameServer启动脚本中有一个自动计算最大堆内存和新生代内存的函数会导致在不同硬件环境下设置最大堆内存和新生代内存环境变量不被应用,这里先提前copy一份容器内部启动脚本做挂载,如果想自定义内存可以自己调整。
1、启动容器
1 2 3 4
| docker run -d \ --privileged=true \ --name rmqnamesrv \ apache/rocketmq:4.9.7 sh mqnamesrv
|
2、复制容器内启动脚本到挂载目录/usr/local/rocketmq/nameserver/bin
1
| docker cp rmqnamesrv:/home/rocketmq/rocketmq-4.9.7/bin/runserver.sh /usr/local/rocketmq/nameserver/bin/runserver.sh
|
3、修改runserver.sh
打开脚本文件
1 2
| vi /usr/local/rocketmq/nameserver/bin/runserver.sh
|
4、停止&删除容器
1 2
| docker stop rmqnamesrv docker rm rmqnamesrv
|
创建Broker需要挂载的文件夹和文件
创建的挂载文件夹
提前创建挂载目录用于挂载容器内部数据、配置文件、以及日志。
创建需要的挂载目录
1
| mkdir /usr/local/rocketmq/broker/{logs,data,conf,bin} -p
|
设置权限
777 文件所属者、文件所属组和其他人有读取 & 写入 & 执行全部权限。rwxrwxrwx
1
| chmod 777 -R /usr/local/rocketmq/broker/*
|
创建broker.conf文件
在/usr/local/rocketmq/broker/conf文件夹下创建broker.conf文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| cat >> /usr/local/rocketmq/broker/conf/broker.conf << EOF
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH EOF
|
通过这个文件把RocketMQ的broker管理起来
拷贝容器内Broker启动脚本到宿主机(如果不需要自定义堆内存可以跳过)
Broker启动脚本中有一个自动计算最大堆内存和新生代内存的函数会导致在不同硬件环境下设置最大堆内存和新生代内存环境变量不被应用,,这里先提前copy一份容器内部启动脚本做挂载,如果想自定义内存可以自己调整。
1、启动容器
1 2 3 4 5
| docker run -d \ --name rmqbroker \ --privileged=true \ apache/rocketmq:4.9.7 \ sh mqbroker
|
2、复制容器内启动脚本到挂载目录/usr/local/rocketmq/nameserver/bin
1
| docker cp rmqbroker:/home/rocketmq/rocketmq-4.9.7/bin/runbroker.sh /usr/local/rocketmq/broker/bin/runbroker.sh
|
3、修改runbroker.sh
打开脚本文件
1
| vi /usr/local/rocketmq/broker/bin/runbroker.sh
|
找到调用calculate_heap_sizes函数的位置注释掉保存即可,拉到脚本最底部就能找到
4、停止&删除容器
1 2
| docker stop rmqbroker docker rm rmqbroker
|
编写docker-compose.yml文件
进入/usr/local/rocketmq目录,创建docker-compose.yml文件,将下面的编排信息写入
1 2
| cd /usr/local/rocketmq vi docker-compose.yml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| version: '3' services: rmqnamesrv: image: apache/rocketmq:4.9.7 container_name: rmqnamesrv ports: - 9876:9876 restart: always privileged: true volumes: - /usr/local/rocketmq/nameserver/logs:/home/rocketmq/logs - /usr/local/rocketmq/nameserver/bin/runserver.sh:/home/rocketmq/rocketmq-4.9.7/bin/runserver.sh environment: - MAX_HEAP_SIZE=256M - HEAP_NEWSIZE=128M command: ["bash","mqnamesrv"] broker: image: apache/rocketmq:4.9.7 container_name: rmqbroker ports: - 10909:10909 - 10911:10911 - 1091:10912 restart: always privileged: true network_mode: "host" volumes: - /usr/local/rocketmq/broker/logs:/home/rocketmq/logs - /usr/local/rocketmq/broker/store:/home/rocketmq/store - /usr/local/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf - /usr/local/rocketmq/broker/bin/runbroker.sh:/home/rocketmq/rocketmq-4.9.7/bin/runbroker.sh depends_on: - 'rmqnamesrv' environment: - NAMESRV_ADDR=rmqnamesrv:9876 - MAX_HEAP_SIZE=2048M - HEAP_NEWSIZE=512M command: ["bash","mqbroker","-c","/home/rocketmq/broker.conf"] rmqdashboard: image: apacherocketmq/rocketmq-dashboard:latest container_name: rocketmq-dashboard ports: - 8080:8080 restart: always privileged: true depends_on: - 'rmqnamesrv' environment: - JAVA_OPTS= -Xmx256M -Xms256M -Xmn128M -Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
|
社区dashboard
1
| docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 -t styletang/rocketmq-console-ng
|
启动服务
docker-compose up -d # -d 指后台运行
启动成功访问控制台
http://192.168.10.220:8080
Broker配置详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
namesrvAddr = 127.0.0.1:6666
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
listenPort=10911
brokerIP1 = 127.0.0.1
brokerIP2 = 127.0.0.1
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
deleteWhen = 04
fileReservedTime = 72
maxMessageSize=4194304
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
transactionTimeout=20
transactionCheckMax=5
transactionCheckInterval=10
|
创建脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| mkdir /usr/local/rocketmq/nameserver/logs -p mkdir /usr/local/rocketmq/nameserver/bin -p mkdir /usr/local/rocketmq/broker/logs -p mkdir /usr/local/rocketmq/broker/data -p mkdir /usr/local/rocketmq/broker/conf -p mkdir /usr/local/rocketmq/broker/bin -p chmod 777 -R /usr/local/rocketmq/nameserver/* chmod 777 -R /usr/local/rocketmq/broker/*
docker run -d \ --privileged=true \ --name rmqnamesrv \ --entrypoint bash \ rocketmq:4.9.7
docker cp rmqnamesrv:/home/rocketmq/rocketmq-4.9.7/bin/runserver.sh /usr/local/rocketmq/nameserver/bin/runserver.sh docker cp rmqnamesrv:/home/rocketmq/rocketmq-4.9.7/bin/runbroker.sh /usr/local/rocketmq/broker/bin/runbroker.sh 去除脚本中磁盘检测 docker stop rmqnamesrv docker rm rmqnamesrv
cat >> /usr/local/rocketmq/broker/conf/broker.conf << EOF
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH EOF
|
使用
1
| export MQ_ADDR=10.233.30.68:9876
|
查看topic列表
1
| sh mqadmin topicList -n $MQ_ADDR
|
创建topic
1
| sh mqadmin updateTopic -c DefaultCluster -n $MQ_ADDR -t xxxxxxx
|
查看消费者组
1
| sh mqadmin consumerProgress -n $MQ_ADDR
|
创建消费者组
1
| sh mqadmin updateSubGroup -n $MQ_ADDR -c DefaultCluster -g xxxxxxx
|
参考:
https://blog.51cto.com/u_16175466/7182537
https://blog.csdn.net/weixin_44606481/article/details/129780540
https://zhuanlan.zhihu.com/p/672809123