📦 Rocket版本 4.9.6

🏢 官方安装文档: https://rocketmq.apache.org/zh/docs/4.x/quickstart/03quickstartWithDockercompose

💻 使用的系统是 ubuntu22.04

🏆 RocketMQ安装之Docker Compose

Docker 安装

⚠️ 最近Docker由于不可抗力Docker 拉取镜像暂时不可用,可使用科学上网和其他仓库代理

请查看https://blog.tanc.fun:9999/archives/e3a559b2-91f2-4645-b6d9-d87d0a4fb954或者https://blog.tanc.fun:9999/archives/1714148055858#%E5%AE%89%E8%A3%85Docker

Docker Compose安装

请查看https://docs.docker.com/compose/install/linux/

Docker Compose 脚本

话说到这人一步的时候搭建 rocketmq服务倒是没什么问题,主要出在 dahsboard

1️⃣ 编写 broker.conf配置文件,注意需要和 docker-compose.yaml文件同目录

🏢 详细的配置文件介绍 https://rocketmq.apache.org/zh/docs/4.x/bestPractice/01bestpractice#broker-%E9%85%8D%E7%BD%AE

brokerClusterName = DefaultCluster ##集群名
brokerName = broker-a  ##broker名
brokerId = 0			##brokerid
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1=填写服务器本机地址
autoCreateTopicEnable=true ##是否自动创建主题

2️⃣ 编写 docker-compose.yaml文档

version: '3.8'
services:
  namesrv:
    image: apache/rocketmq:4.9.6 ##namesrver 镜像
    container_name: rmqnamesrv
    ports:
      - 9876:9876 ##暴露端口
    networks:
      - rocketmq
    command: sh mqnamesrv ##运行

  broker:
    image: apache/rocketmq:4.9.6 ##broker 镜像
    container_name: rmqbroker
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      - NAMESRV_ADDR=rmqnamesrv:9876
    volumes: ##将写好的broker文件映射
      - ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf
    depends_on:
      - namesrv
    networks:
      - rocketmq
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf

  dashboard: ##rocketmq dashboard
    image: apacherocketmq/rocketmq-dashboard:latest
    container_name: rmqdashabord
    ports:
      - 9090:8080
    environment:  ##这里需要指定nameserver的地址也就是rmqnamesrv
      - JAVA_OPTS=-Drocketmq.namesrv.addr=rmqnamesrv:9876  -Dcom.rocketmq.sendMessageWithVIPChannel=false
    depends_on:
      - namesrv
      - broker
    networks:
      - rocketmq


networks:
  rocketmq:
    driver: bridge

3️⃣ 运行命令

root@Tc-Server:/mnt/d/example/docker-compose/rocketmq/4.9.6# docker compose up -d
WARN[0000] /mnt/d/example/docker-compose/rocketmq/4.9.6/docker-compose.yaml: `version` is obsolete
[+] Running 4/4
 ✔ Network 496_rocketmq    Created                                                               0.2s
 ✔ Container rmqnamesrv    Started                                                               0.5s
 ✔ Container rmqbroker     Started                                                               0.9s
 ✔ Container rmqdashabord  Started                                                               1.3s
 
 
 ##查看是否运行
 root@Tc-Server:/mnt/d/example/docker-compose/rocketmq/4.9.6# docker compose ps -a
WARN[0000] /mnt/d/example/docker-compose/rocketmq/4.9.6/docker-compose.yaml: `version` is obsolete
NAME           IMAGE                                      COMMAND                  SERVICE     CREATED          STATUS          PORTS
rmqbroker      apache/rocketmq:4.9.6                      "sh mqbroker -c /hom…"   broker      20 minutes ago   Up 10 minutes   0.0.0.0:10909->10909/tcp, :::10909->10909/tcp, 9876/tcp, 0.0.0.0:10911-10912->10911-10912/tcp, :::10911-10912->10911-10912/tcp
rmqdashabord   apacherocketmq/rocketmq-dashboard:latest   "sh -c 'java $JAVA_O…"   dashboard   20 minutes ago   Up 10 minutes   0.0.0.0:9090->8080/tcp, :::9090->8080/tcp
rmqnamesrv     apache/rocketmq:4.9.6                      "sh mqnamesrv"           namesrv     20 minutes ago   Up 10 minutes   10909/tcp, 0.0.0.0:9876->9876/tcp, :::9876->9876/tcp, 10911-10912/tcp

4️⃣ 查看 Dashboard是否可以正常访问

访问地址为 主机ip:9090

image-20240731214828026

安装需要注意点

内存

nameserverbroker启动的时候会判断你本机的内存,然后自动分配内存,如果你觉得太大可以自动修改,在 runserver.shrunbroker.sh内,docker部署和本机部署的配置文件不一样