利用docker部署RocketMQ

starlin 4,108 2021-06-03

下载rocketmq docker版

  1. 找个目录,在cmd下执行以下命令:
git clone https://github.com/apache/rocketmq-docker.git

cd image-build
sh build-image.sh 4.5.0 alpine
  1. 返回上级目录,执行以下命令
cd ..
sh stage.sh 4.5.0
  1. 切换到docker-compose目录,修改docker-compose.yml,增加console image,注释broker1如下:
version: '2'
services:
  #Service for nameserver
  namesrv:
    image: apacherocketmq/rocketmq:4.5.0
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    volumes:
      - ./data/namesrv/logs:/home/rocketmq/logs
    command: sh mqnamesrv

  #Service for broker
  broker:
    image: apacherocketmq/rocketmq:4.5.0
    container_name: rmqbroker
    links:
      - namesrv
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      - NAMESRV_ADDR=namesrv:9876
    volumes:
      - ./data/broker/logs:/home/rocketmq/logs
      - ./data/broker/store:/home/rocketmq/store
      - ./data/broker/conf/broker.conf:/opt/rocketmq-4.5.0/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq-4.5.0/conf/broker.conf

  rocketmq-console:
    image: styletang/rocketmq-console-ng
    container_name: rocketmq-console
    hostname: rocketmq-console
    ports:
      - 6060:8080
    environment:
      JAVA_OPTS: "-Xms128m -Xmx128m -Xmn64m -Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - namesrv

  #Service for another broker -- broker1
  # broker1:
  #   image: apacherocketmq/rocketmq:4.5.0
  #   container_name: rmqbroker-b
  #   links:
  #     - namesrv
  #   ports:
  #     - 10929:10909
  #     - 10931:10911
  #     - 10932:10912
  #   environment:
  #     - NAMESRV_ADDR=namesrv:9876
  #   volumes:
  #     - ./data1/broker/logs:/home/rocketmq/logs
  #     - ./data1/broker/store:/home/rocketmq/store
  #     - ./data1/broker/conf/broker.conf:/opt/rocketmq-4.5.0/conf/broker.conf
  #   command: sh mqbroker -c /opt/rocketmq-4.5.0/conf/broker.conf

可以在linux下修改,也可以在目录中修改

启动RocketMQ容器

最后启动MQ容器,命令如下:

docker-compose up -d

启动成功后如下:

Creating rmqnamesrv ... done
Creating rmqbroker        ... done
Creating rocketmq-console ... done

打开http://localhost:6060/,就能看到mq的console界面,则表示部署成功


# RocketMQ