Docker里面运行RocketMQ

2022-11-302234

1.准备文件夹和配置

创建指定文件夹

mkdir -p rocketmq/namesrv/store
mkdir -p rocketmq/namesrv/logs
mkdir -p rocketmq/broker/store
mkdir -p rocketmq/broker/logs
mkdir -p rocketmq/broker/conf
# 这两个可以先不管
mkdir -p rocketmq/rocketmq-dashboard/data
mkdir -p rocketmq/rocketmq-dashboard/logs

## 配置broker配置文件
vi rocketmq/broker/conf/broker.conf

配置broker.conf

# broker.conf
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = MyCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
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 = 192.168.223.233
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95

2.写rocketmq-docker-compose.yml

通过Docker-compose 进行配置启动

# rocketmq-docker-compose.yml
version: '3.9'
services:
  mqnamesrv:
    image: apache/rocketmq:4.9.4
    container_name: mqnamesrv
    restart: always
    ports:
      - 9876:9876
    volumes:
      - ./rocketmq/namesrv/logs:/root/logs
      - ./rocketmq/namesrv/store:/root/store
    environment: 
      - MAX_POSSIBLE_HEAP=1024m
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn128m
    command: sh mqnamesrv

  mqbroker:
    image: apache/rocketmq:4.9.4
    container_name: mqbroker
    restart: always
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    volumes:
      - ./rocketmq/broker/logs:/root/logs
      - ./rocketmq/broker/store:/root/store
      - ./rocketmq/broker/conf/broker.conf:/opt/rocketmq-4.9.4/conf/broker.conf
    command: sh mqbroker -n mqnamesrv:9876 -c /opt/rocketmq-4.9.4/conf/broker.conf
    depends_on:
      - mqnamesrv
    environment:
      - MAX_POSSIBLE_HEAP=1024m
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn128m
  rocketmq-dashboard:
    image: apacherocketmq/rocketmq-dashboard:1.0.0
    container_name: rocketmq-dashboard
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - mqnamesrv
    environment:
      - JAVA_OPTS=-Dlogging.level.root=info -Drocketmq.namesrv.addr=mqnamesrv:9876 
      - MAX_POSSIBLE_HEAP=1024m
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn128m

# 启动
docker-compose -f ./rocketmq-docker-compose.yml up -d

一些环境变量说明

##     指定namesrv的地址为本机namesrv的ip地址:9876
NAMESRV_ADDR=namesrv:9876

## 设置最大内存
MAX_POSSIBLE_HEAP=1024m

## jvm 参数
JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn128m

## 开启自动创建主题
autoCreateTopicEnable=true

## 非vip通道端口
10911:10911

## vip通道端口
10909:10909

## 指定broker配置文件
-c /opt/rocketmq-4.9.4/conf/broker.conf

## 配置消息是否通过vip发送
-Dcom.rocketmq.sendMessageWithVIPChannel=false
分享
点赞0
打赏
上一篇:Docker常用命令笔记(一)
下一篇:自定义Spring容器工具类