Docker部署RocketMQ
不说废话,直接动手!!!
不说废话,直接动手!!!
不说废话,直接动手!!!
Docker部署RocketMQ
环境配置
程序猿,你懂得,阿里服务器,CPU 1核, 内存2G
服务器环境
[root@Genterator ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
1 Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz
[root@Genterator ~]# cat /proc/meminfo | grep MemTotal
MemTotal: 1790344 kB
Docker环境
[root@Genterator ~]# docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:03:45 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:21 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683
RocketMQ部署
RocketMQ版本
选择MQ镜像
[root@Genterator ~]# docker search rocketmq
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
foxiswho/rocketmq rocketmq 61
rocketmqinc/rocketmq Image repository for Apache RocketMQ 52
styletang/rocketmq-console-ng rocketmq-console-ng 35
apacherocketmq/rocketmq Docker Image for Apache RocketMQ 19
rocketmqinc/rocketmq-broker Customized RocketMQ Broker Image for RocketM… 10
rocketmqinc/rocketmq-namesrv Customized RocketMQ Name Server Image for Ro… 8
apacherocketmq/rocketmq-console This repo has moved to rocketmq-dashboard, w… 6
xlxwhy/rocketmq alibaba's rocketmq 4
leixuewen/rocketmq 基于 rocketmq 最新版制作,可快速部署单机和集群 4
king019/rocketmq rocketmq 3
apacherocketmq/rocketmq-broker Apache RocketMQ docker image for broker. 3
apacherocketmq/rocketmq-nameserver Apache RocketMQ docker image for name server. 2
pangliang/rocketmq-console-ng 2
toyangdon/rocketmq-broker 1
dyrnq/rocketmq This is a rocketmq docker image based AdoptO… 1
huanwei/rocketmq 1
apacherocketmq/rocketmq-operator RocketMQ Operator is to manage RocketMQ serv… 1
coder4/rocketmq rocketmq 1 [OK]
2019liurui/rocketmq-broker RocketMQ broker image for RocketMQ-Operator 1
apacherocketmq/rocketmq-dashboard Docker Image for Apache RocketMQ Dashboard 1
pengzu/rocketmq-console-ng web console for rocketmq ,this code is from … 0
2019liurui/rocketmq-operator Kubernetes Operator for RocketMQ ! 0
rocketmqinc/rocketmq-operator The Kubernetes operator for RocketMQ 0
chaiyd/rocketmq Apache RocketMQ™ is a unified messaging engi… 0
pureinsights/rocketmq-broker 0
没有官方镜像,我就选了个rocketmqinc/rocketmq
的镜像,这玩意儿差别不太大,选择适合自己的,适合自己的!!!
选择镜像版本
[root@Genterator ~]# curl https://registry.hub.docker.com/v1/repositories/rocketmqinc/rocketmq/tags\
> | tr -d '[\[\]" ]' | tr '}' '\n'\
> | awk -F: -v image='rocketmqinc/rocketmq' '{if(NR!=NF && $3 != ""){printf("%s:%s\n",image,$3)}}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 387 0 387 0 0 283 0 --:--:-- 0:00:01 --:--:-- 283
rocketmqinc/rocketmq:latest
rocketmqinc/rocketmq:4.0.0-incubating
rocketmqinc/rocketmq:4.2.0
rocketmqinc/rocketmq:4.3.0
rocketmqinc/rocketmq:4.3.1
rocketmqinc/rocketmq:4.3.1-k8s
rocketmqinc/rocketmq:4.3.2
rocketmqinc/rocketmq:4.3.2-k8s
rocketmqinc/rocketmq:4.3.3-k8s
rocketmqinc/rocketmq:4.4.0
还是那话:选择适合自己的,适合自己的!!!
组件部署
RocketMQ主要有两大组件:NameServer组件、Broker组件,不懂得建议先了解RocketMQ结构!!!
此次部署采用1 NameServer + 2 Broker(1 master + 1 slaver)
结构,这渣渣的服务器配置,量力而行!!!
如果你的服务器也不咋地,建议选择1 NameServer + 1 Broker(1 master)
,玩玩就行了!
如果你的服务器不错,则建议2 NameServer + 3 Broker(1 master + 2 slaver)
,玩起来更爽!!!
声明:
为了省事:
- 采用
shell
脚本自动创建、运行docker,里面包含了存储路径和docker run运行命令 - 日志和数据均存放于
/opt/volume/rocket/data
目录下:
废话不多说,开干!!!
NameServer部署
NameServer直接使用命令启动即可:
docker run -itd --privileged=true --restart=always \
--name rmqnamesrv -p 9876:9876 \
-v /opt/volume/rocketmq/data/namesrv/logs:/root/logs \
-v /opt/volume/rocketmq/data/namesrv/store:/root/store \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m" \
rocketmqinc/rocketmq \
sh mqnamesrv
也可以像我一样,直接用shell
脚本文件创建文件夹、运行:
Broker部署
Broker部署两台,一台为master、一台为slaver,部署方式都差不多,只是稍微有点出入,这里也有一个坑,后面说!
两台broker分别命名为broker-a-0
和broker-a-1
,最后0和1用于区分主从,0为主master,1为从slaver
master:broker-a-0
我使用config配置文件
+ shell脚本启动命令
方式:
- broker-a-0.conf文件
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = Gen_Cluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId=0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 01
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址
# brokerIP1 = 172.17.0.3
# 设置监听端口
listenPort=10911
- shell脚本
Docker启动命令
docker run -itd --restart=always --name rmqbroker-a-0 \
--link rmqnamesrv:rmqnamesrv -p 10911:10911 -p 10909:10909 \
-v /opt/volume/rocketmq/data/broker-a/0/logs:/root/logs \
-v /opt/volume/rocketmq/data/broker-a/0/store:/root/store \
-v $(pwd)/broker-a-0.conf:/docker/rocketmq/conf/broker.conf \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m" \
rocketmqinc/rocketmq \
sh mqbroker -c /docker/rocketmq/conf/broker.conf
slaver:broker-a-1
依然使用config配置文件+ shell脚本启动命令方式:
- boker-a-1.config
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = Gen_Cluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId = 1
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 01
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址
# brokerIP1 = 172.17.0.4
# Broker对外服务的监听端口
listenPort=10921
# Broker为从节点时,必须指定角色
brokerRole=SLAVE
注意:
# Broker为从节点时,必须指定角色
brokerRole=SLAVE
一定一定要设置,不然会出现注册为master!谨记!!!
一定一定要设置,不然会出现注册为master!谨记!!!
一定一定要设置,不然会出现注册为master!谨记!!!
- 启动脚本
Docker启动命令
docker run -itd --restart=always --name rmqbroker-a-1 \
--link rmqnamesrv:rmqnamesrv -p 10921:10911 -p 10929:10909 \
-v /opt/volume/rocketmq/data/broker-a/1/logs:/root/logs \
-v /opt/volume/rocketmq/data/broker-a/1/store:/root/store \
-v $(pwd)/broker-a-1.conf:/docker/rocketmq/conf/broker.conf \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m" \
rocketmqinc/rocketmq \
sh mqbroker -c /docker/rocketmq/conf/broker.conf
至此,RocketMQ就部署好了,可以通过打印日志的方式查看注册情况,也可以使用图形界面进行查看!
Web端部署
无力吐槽RocketMQ,没有自己的图形管理界面,大部分均使用开源的RocketMQ-Console
项目,进行图形化管理。此处使用styletang/rocketmq-console-ng
镜像
不需要其他配置,启动链接到NameServer即可,为图方便,我依然使用shell脚本启动:
启动命令:
# 创建RokectMQ-console命令
docker run -itd --name rmqconsole \
-p 8090:8080 --link rmqnamesrv:namesrv \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-e "JAVA_OPT_EXT=-server -Xms256m -Xmx256m" \
-t styletang/rocketmq-console-ng /bin/bash
至此,RokcetMQ-Console已经部署好了,我使用8090的端口,浏览器访问:http://xxx.xxx.xxx.xxx:8090
至此,RocketMQ和RocketMQ-Console的Docker容器部署至此结束,跟着代码撸一遍,基本应该没啥大问题了,实在不想复制的,那就下载吧:
https://download.csdn.net/download/u010088278/47332135