docker-compose 部署单节点rocketMQ(本地环

2023-07-30  本文已影响0人  程序猿TT

RocketMQ搭建(本地环境)

1. 准备(本地环境)

host设置 (/etc/hosts)

127.0.0.1 host.docker.internal

目的:让本地服务可以正常访问服务

2. 启动服务

broker.conf

#broker1服务器配置
 
brokerClusterName = DefaultCluster
 
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = rocketmq-broker
 
#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 = host.docker.internal
 
#broker服务端口
listenPort = 10911

docker-compose.yaml

version: "3.3"
 
services:
  rocketmq-namesrv:
    image: apache/rocketmq:4.9.7
    restart: always
    container_name: rocketmq-namesrv
    ports:
      - "9876:9876"
    volumes:
      - ./logs/nameserver1:/home/rocketmq/logs/rocketmqlogs
    command: sh mqnamesrv
    networks:
      - rocketmq
  rocketmq-broker:
    image: apache/rocketmq:4.9.7
    restart: always
    container_name: rocketmq-broker
    ports:
      - "10911:10911"
    volumes:
      - ./logs/broker:/home/rocketmq/logs/rocketmqlogs
      - ./conf/broker.conf:/home/rocketmq/rocketmq-4.9.7/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rocketmq-namesrv:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.7/conf/broker.conf autoCreateTopicEnable=true &
    depends_on:
      - rocketmq-namesrv
    networks:
      - rocketmq
  rocketmq-console:
    image: apacherocketmq/rocketmq-console:2.0.0
    restart: always
    container_name: rocketmq-console
    ports:
      - "9090:8080"
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=rocketmq-namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      - rocketmq
    depends_on:
      - rocketmq-broker

 
networks:
  rocketmq:
    driver: bridge

启动服务

docker-compose up -d
❯ docker-compose up -d
[+] Running 3/0
 ⠿ Container rocketmq-namesrv  Running                                     0.0s
 ⠿ Container rocketmq-broker   Running                                     0.0s
 ⠿ Container rocketmq-console  Running                                     0.0s

3. 验证服务

访问:http://localhost:9090/#/

image.png
上一篇下一篇

猜你喜欢

热点阅读