docker 安裝 rocketmq 5.2.0

LiuChengloong發表於2024-05-28
sudo mkdir -p /opt/rocketmq/conf/broker
sudo mkdir -p /opt/rocketmq/conf/namesrv
sudo mkdir -p /opt/rocketmq/data/broker

### nameservice.conf
listenPort: 9876
storePathRootDir: /opt/rocketmq-5.2.0/store

### broker.conf
# 叢集名稱
brokerClusterName = DefaultCluster
# 節點名稱
brokerName = rocketmq-broker
# broker id節點ID, 0 表示 master, 其他的正整數表示 slave,不能小於0 
brokerId = 0
# Broker服務地址    String 內部使用填內網ip,如果是需要給外部使用填公網ip,自行更改
brokerIP1 = x.x.x.x
# Broker角色
brokerRole = ASYNC_MASTER
# 刷盤方式
flushDiskType = ASYNC_FLUSH
# 在每天的什麼時間刪除已經超過檔案保留時間的 commit log,預設值04
deleteWhen = 04
# 以小時計算的檔案保留時間 預設值72小時
fileReservedTime = 72
# 是否允許Broker 自動建立Topic,建議線下開啟,線上關閉
autoCreateTopicEnable = true
# 是否允許Broker自動建立訂閱組,建議線下開啟,線上關閉
autoCreateSubscriptionGroup = true
#開啟多佇列分發特性
enableLmq = true
enableMultiDispatch = true

### docker-compose.yml
version: '3.7'
services:
  # NameServer 服務
  rocketmq-namesrv:
    image: apache/rocketmq:5.2.0
    container_name: rocketmq-namesrv
    ports:
      - "9876:9876"  # 對映 NameServer 的埠
    volumes:
      - ./conf/namesrv:/opt/rocketmq-5.2.0/conf  # 對映配置檔案目錄
    command: sh mqnamesrv # 啟動 NameServer
    environment:
      - TZ=Asia/Shanghai

  # Broker 服務
  rocketmq-broker:
    image: apache/rocketmq:5.2.0
    container_name: rocketmq-broker
    depends_on:
      - rocketmq-namesrv  # 依賴於 NameServer 啟動完畢
    ports:
      - "10911:10911"  # 對映 Broker 的埠
      - "10909:10909"  # 對映 Broker 的 HA 埠
      - "8081:8081"
    volumes:
      - ./conf/broker:/opt/rocketmq-5.2.0/conf
      # 對映配置檔案目錄
    command: sh mqbroker -c /opt/rocketmq-5.2.0/conf/broker.conf -n rocketmq-namesrv:9876 --enable-proxy autoCreateTopicEnable=true # 啟動 Broker
    environment:
      - TZ=Asia/Shanghai

  # RocketMQ Console 服務
  rocketmq-console:
    image: styletang/rocketmq-console-ng
    container_name: rocketmq-console
    ports:
      - "8083:8080"  # 對映 RocketMQ Console 的埠
    environment:
      - rocketmq.config.namesrvAddr=rocketmq-namesrv:9876  # 配置 RocketMQ Console 連線的 NameServer 地址
      - TZ=Asia/Shanghai