首页 > 其他分享 >Docker部署RocketMQ集群

Docker部署RocketMQ集群

时间:2023-02-23 19:45:24浏览次数:62  
标签:opt broker 集群 RocketMQ conf home Docker rmqnamesrv rocketmq

一、概述

Apache RocketMQ是阿里开源的一款高性能、高吞吐量、队列模型的消息中间件的分布式消息中间件。

关于RocketMQ集群架构的详细介绍,请参考链接:https://blog.csdn.net/Weixiaohuai/article/details/123607472

 

二、下载镜像

docker pull apache/rocketmq:4.9.4
docker pull apacherocketmq/rocketmq-dashboard

主要用到了2个镜像,第1个用来部署NameServer和Broker,第2个用来管理rocketmq

 

三、部署

本文主要采用一台服务器来部署RocketMQ集群,集群部署模式采用多master模式,也就是2个NameServer和2个Broker

刷盘机制采用异步复制,异步刷盘

 

服务器配置:

操作系统:centos 7.6

硬件配置:2核4g

ip地址:192.168.137.138

 

创建目录

mkdir -p /opt/rocketmq/logs/nameserver-a
mkdir -p /opt/rocketmq/logs/nameserver-b
mkdir -p /opt/rocketmq/logs/broker-a
mkdir -p /opt/rocketmq/logs/broker-b
mkdir -p /opt/rocketmq/store/broker-a
mkdir -p /opt/rocketmq/store/broker-b
mkdir -p /opt/rocketmq/broker-a/
mkdir -p /opt/rocketmq/broker-b/

设置权限

chmod 777 -R /opt/rocketmq/logs/*
chmod 777 -R /opt/rocketmq/store/*

注意:这里如果不设置权限,会导致docker写入文件失败,导致rocketmq启动异常。

 

创建broker.conf

修改第一个节点配置

vim /opt/rocketmq/broker-a/broker-a.conf

内容如下:

brokerClusterName = rocketmq-cluster
brokerName = broker-a
brokerId = 0
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)
#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。
brokerIP1 = 192.168.137.138
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=192.168.137.138:9876;192.168.137.138:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10911
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

注意:brokerIP1,namesrvAddr,这2个参数,一般配置为内网ip,提供内网访问。如果需要公网访问,这里一定要配置公网ip,否则无法访问。

 

修改第二个节点配置

vim /opt/rocketmq/broker-b/broker-b.conf

内容如下:

brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 0
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)
#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。
brokerIP1 = 192.168.137.138
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=192.168.137.138:9876;192.168.137.138:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10912
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
View Code

注意:brokerName,listenPort这2个参数和第一个节点不一样,其他内容和第一个节点配置一样

 

编写 docker-compose.yml

vim /opt/rocketmq/docker-compose.yml

内容如下:

version: '3.5'
services:
  rmqnamesrv-a:
    image: apache/rocketmq:4.9.4
    container_name: rmqnamesrv-a
    ports:
      - 9876:9876
    volumes:
      #- /opt/rocketmq/logs/nameserver-a:/home/rocketmq/logs
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    command: sh mqnamesrv
    networks:
      rmq:
        aliases:
          - rmqnamesrv-a

  rmqnamesrv-b:
    image: apache/rocketmq:4.9.4
    container_name: rmqnamesrv-b
    ports:
      - 9877:9876
    volumes:
      #- /opt/rocketmq/logs/nameserver-b:/home/rocketmq/logs
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    command: sh mqnamesrv
    networks:
      rmq:
        aliases:
          - rmqnamesrv-b

  rmqbroker-a:
    image: apache/rocketmq:4.9.4
    container_name: rmqbroker-a
    ports:
      - 10911:10911
    volumes:
      #- /opt/rocketmq/logs/broker-a/logs:/home/rocketmq/logs
      #- /opt/rocketmq/store/broker-a/store:/home/rocketmq/store
      - /opt/rocketmq/broker-a/broker-a.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rmqnamesrv-a:9876"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-a

  rmqbroker-b:
    image: apache/rocketmq:4.9.4
    container_name: rmqbroker-b
    ports:
      - 10912:10912
    volumes:
      #- /opt/rocketmq/logs/broker-b/logs:/home/rocketmq/logs
      #- /opt/rocketmq/store/broker-b/store:/home/rocketmq/store
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rmqnamesrv-b:9877"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-b
  rmqconsole:
    image: apacherocketmq/rocketmq-dashboard
    container_name: rmqconsole
    ports:
      - 8087:8080
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.accessKey=rocketmq2 -Drocketmq.config.secretKey=12345678
    volumes:
      - /opt/rocketmq/console-ng/data:/tmp/rocketmq-console/data
    networks:
      rmq:
        aliases:
          - rmqconsole
networks:
  rmq:
    name: rmq
    driver: bridge
View Code

 

最后一步,执行docker-compose

cd /opt/rocketmq
docker-compose up -d

 

查看进程,使用命令docker-compose ps

# docker-compose ps
    Name                  Command               State                Ports              
----------------------------------------------------------------------------------------
rmqbroker-a    sh mqbroker -c /home/rocke ...   Up      10909/tcp,                      
                                                        0.0.0.0:10911->10911/tcp,       
                                                        10912/tcp, 9876/tcp             
rmqbroker-b    sh mqbroker -c /home/rocke ...   Up      10909/tcp, 10911/tcp,           
                                                        0.0.0.0:10912->10912/tcp,       
                                                        9876/tcp                        
rmqconsole     sh -c java $JAVA_OPTS -jar ...   Up      0.0.0.0:8087->8080/tcp          
rmqnamesrv-a   sh mqnamesrv                     Up      10909/tcp, 10911/tcp, 10912/tcp,
                                                        0.0.0.0:9876->9876/tcp          
rmqnamesrv-b   sh mqnamesrv                     Up      10909/tcp, 10911/tcp, 10912/tcp,
                                                        0.0.0.0:9877->9876/tcp 

确保State状态为up

 

访问管理平台

http://192.168.137.138:8087

点击右上角切换语言为简体中文,点击集群,效果如下:

 

看到这个图,说明集群启动正常。

 

设置持久化配置

上面的 docker-compose.yml,注释掉了一些文件挂载操作,因为新版本的rocketmq无法启动创建文件,直接挂载一个空目录,会启动报错。

 

复制docker里面的文件

docker cp rmqnamesrv-a:/home/rocketmq/logs /opt/rocketmq/logs/nameserver-a
docker cp rmqnamesrv-b:/home/rocketmq/logs /opt/rocketmq/logs/nameserver-b
docker cp rmqbroker-a:/home/rocketmq/logs /opt/rocketmq/logs/broker-a
docker cp rmqbroker-a:/home/rocketmq/store /opt/rocketmq/store/broker-a
docker cp rmqbroker-b:/home/rocketmq/logs /opt/rocketmq/logs/broker-b
docker cp rmqbroker-b:/home/rocketmq/store /opt/rocketmq/store/broker-b

设置权限,否则会写入文件失败,造成启动失败。

chmod 777 -R /opt/rocketmq/logs/*
chmod 777 -R /opt/rocketmq/store/*

 

关闭相关docker进程

docker-compose down

 

修改docker-compose.yml,开启持久化配置

version: '3.5'
services:
  rmqnamesrv-a:
    image: apache/rocketmq:4.9.4
    container_name: rmqnamesrv-a
    ports:
      - 9876:9876
    volumes:
      - /opt/rocketmq/logs/nameserver-a:/home/rocketmq/logs
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    command: sh mqnamesrv
    networks:
      rmq:
        aliases:
          - rmqnamesrv-a

  rmqnamesrv-b:
    image: apache/rocketmq:4.9.4
    container_name: rmqnamesrv-b
    ports:
      - 9877:9876
    volumes:
      - /opt/rocketmq/logs/nameserver-b:/home/rocketmq/logs
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    command: sh mqnamesrv
    networks:
      rmq:
        aliases:
          - rmqnamesrv-b

  rmqbroker-a:
    image: apache/rocketmq:4.9.4
    container_name: rmqbroker-a
    ports:
      - 10911:10911
    volumes:
      - /opt/rocketmq/logs/broker-a/logs:/home/rocketmq/logs
      - /opt/rocketmq/store/broker-a/store:/home/rocketmq/store
      - /opt/rocketmq/broker-a/broker-a.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rmqnamesrv-a:9876"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-a

  rmqbroker-b:
    image: apache/rocketmq:4.9.4
    container_name: rmqbroker-b
    ports:
      - 10912:10912
    volumes:
      - /opt/rocketmq/logs/broker-b/logs:/home/rocketmq/logs
      - /opt/rocketmq/store/broker-b/store:/home/rocketmq/store
      - /opt/rocketmq/broker-b/broker-b.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rmqnamesrv-b:9877"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-b
  rmqconsole:
    image: apacherocketmq/rocketmq-dashboard
    container_name: rmqconsole
    ports:
      - 8087:8080
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.accessKey=rocketmq2 -Drocketmq.config.secretKey=12345678
    volumes:
      - /opt/rocketmq/console-ng/data:/tmp/rocketmq-console/data
    networks:
      rmq:
        aliases:
          - rmqconsole
networks:
  rmq:
    name: rmq
    driver: bridge
View Code

 

启动相关docker进程

docker-compose up -d

 

等待30秒,再次访问管理后台,如果数据能显示,表示正常。

 

测试

点击主题,默认是空的

点击新增

 

 选择集群,BROKER_NAME,输入主题名test

 

点击提交后,会出现一条数据,点击发送消息

 

 点击提交

 

 提示成功

 

 点击消息,选择主题test,点击搜索,就可以看到发送记录了。

 

 

 

本文参考链接:

https://www.136.la/jingpin/show-176132.html

 

标签:opt,broker,集群,RocketMQ,conf,home,Docker,rmqnamesrv,rocketmq
From: https://www.cnblogs.com/xiao987334176/p/16771899.html

相关文章

  • 05. Kubernetes - 集群安装(二进制)
    安装准备区别于使用kubeadm部署集群时所有核心组件都托管在集群上。二进制安装则采用守护进程的方式直接将各个组件运行在宿主机,生产环境更为推荐。服务还是那些,只需要......
  • docker 操作笔记
    1.Docker创建ubuntu系统更换apt-get源创建Dockerfile并且更新apt源在Dockerfile中添加如下两句代码:RUNsed-is@/archive.ubuntu.com/@/mirrors.aliyun.com/@g/et......
  • K8s集群离线环境部署
    1.环境说明虚拟机工具:VirtualBox7.0虚拟机操作系统:Centos7(CentOS-7-x86_64-Minimal-2003.iso)虚拟机配置:2核CPU、2G内存、40G硬盘虚拟机网络模式:仅主机(Host-Only)网络,......
  • Windows 上 Docker 部署 MongoDb 并构建数据持久化
    拉取镜像老样子先拉取一个镜像。dockerpullmongo:latest运行容器dockerrun-p27017:27017--namemongo-v/d/mongo/data:/data/db-eMONGO_INITDB_ROOT_USERNA......
  • 在 code-server Docker Container 使用 host user/group 账户
      在code-serverDockerContainer使用hostuser/group账户(jgsun.github.io) Overview“工欲善其事,必先利其器!”此文为 定制code-serverdockerimage ......
  • 以docker方式部署的redis键值查询及清理
     1、首先使用 dockerps 命令来查看正在运行的容器。该命令会列出容器的ID、名称、端口号、状态等信息。也可以使用 dockerps-a 命令来查看所有容器,包括已经停止的......
  • 集群调度LSF-学习笔记
    集群-------多台设备HPC集群----多台用于计算的设备集群调度-LSF:LSF是一种强大的工作负载管理平台,提供基于各种策略的智能调度功能,利用分布式的基础架构资源来提高整体的......
  • 一次docker启动错误unable to configure the Docker daemon with file /etc/docker/da
    环境:三台服务器,一台daemon可以启动,另外两台不行解决原因:服务器内有两个docker.service,其中一个有配置--insecure-registry=127.0.0.1,重命名后启动docker可用报错如下:2月......
  • docker卸载提示Device or resource busy
    1. 停掉运行的容器,停掉docker先停掉全部运行的容器,并删除dockerkill$(dockerps-a-q)##删除所有的docker容器dockerrm$(dockerps-a-q)##删除所有的docker镜......
  • docker基本操作
     【1】常见操作本地镜像:dockerimages容器列表:dockerps-a从镜像创建容器:dockerrun...启动所有容器:dockerstart$(dockerps-a|awk'{print$1}'|tail......