【环境搭建】linux docker-compose安装rocketmq

创建目录

mkdir -p /data/docker/rocketmq/namesrv/logs
mkdir -p /data/docker/rocketmq/broker1/conf
mkdir -p /data/docker/rocketmq/broker1/logs
mkdir -p /data/docker/rocketmq/broker1/store

给权限

chmod -R 777 /data/docker/rocketmq

创建配置文件

cd /data/docker/rocketmq/broker1/conf

vi broker.conf

broker.conf

# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker1
#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地址(**这个非常重要,主从模式下,从节点会根据主节点的brokerIP2来同步数据,如果不配置,主从无法同步,brokerIP1设置为自己外网能访问的ip,服务器双网卡情况下必须配置,比如阿里云这种,主节点需要配置ip1和ip2,从节点只需要配置ip1即可)
# 此ip由使用环境决定 本机使用 127 局域网使用 192 外网使用 外网ip
brokerIP1 = 公网ip
#nameServer地址,分号分割
namesrvAddr = 公网ip:9876
#Broker 对外服务的监听端口,
listenPort = 10911
#是否允许Broker自动创建Topic
autoCreateTopicEnable = true
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = true
#linux开启epoll
useEpollNativeSelector = true

 /data/docker/rocketmq目录创建配置文件docker-compose.yml

version: "3"
services:
  mqnamesrv:
    image: apache/rocketmq:4.9.4
    container_name: mqnamesrv
    ports:
      - "9876:9876"
    environment:
      TZ: Asia/Shanghai
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m"
    command: sh mqnamesrv
    volumes:
      - /data/docker/rocketmq/namesrv/logs:/home/rocketmq/logs/rocketmqlogs
    networks:
      rmq:
        aliases:
          - mqnamesrv

  mqbroker1:
    image: apache/rocketmq:4.9.4
    container_name: mqbroker1
    ports:
      - "10911:10911"
      - "10909:10909"
      - "10912:10912"
    environment:
    	TZ: Asia/Shanghai
    	JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    depends_on:
      - mqnamesrv
    volumes:
      - /data/docker/rocketmq/broker1/conf/broker.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
      - /data/docker/rocketmq/broker1/logs:/home/rocketmq/logs/rocketmqlogs
      - /data/docker/rocketmq/broker1/store:/home/rocketmq/store
    networks:
      rmq:
        aliases:
          - mqbroker1

  mqconsole:
    image: styletang/rocketmq-console-ng
    container_name: mqconsole
    ports:
      - "19876:19876"
      - "8080:8080"
    environment:
      TZ: Asia/Shanghai
      #密码没生效,待核查
      JAVA_OPTS: "-Drocketmq.namesrv.addr=mqnamesrv:9876; -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.accessKey=admin -Drocketmq.config.secretKey=password"
    depends_on:
      - mqnamesrv
    networks:
      rmq:
        aliases:
          - mqconsole


networks:
  rmq:
    name: rmq
    driver: bridge

启动

docker-compose up -d mqnamesrv mqbroker1 mqconsole

http://ip​​​​​​9:8080/#/可看控制台

你可能感兴趣的:(环境搭建,linux,docker,rocketmq)