docker搭建rocketmq环境

1、安装docker-compose

# 下载docker-compose
curl -L https://github.com/docker/compose/releases/download/1.27.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# 分配权限
chmod +x /usr/local/bin/docker-compose
# 查看版本
docker-compose --version

2、拉取相应镜像

# 拉取rocketmq
docker pull apacherocketmq/rocketmq
# 拉取rocketmq-dashboard
docker pull apacherocketmq/rocketmq-dashboard

3、环境部署

3.1 NameSrvDocker宿主机环境,主要配置的是日志路径以及存储路径
mkdir -p /root/rocketmq/data/namesrv/logs
mkdir -p /root/rocketmq/data/namesrv/store
3.2 BrokerDocker宿主机环境,主要创建日志、数据存储、以及配置存放的挂载路径
mkdir -p /root/rocketmq/data/broker/logs
mkdir -p /root/rocketmq/data/broker/store
mkdir -p /root/rocketmq/etc/broker
3.3 Broker配置文件创建,并配置如下内容
vim /root/rocketmq/etc/broker/broker.conf

输入内容:
brokerClusterName = mxsm-docker
brokerName = mxsm-docker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 自动创建topic
autoCreateTopicEnable=true
# Docker环境需要设置成宿主机IP
#brokerIP1 = {docker宿主机IP}
brokerIP1 = 192.168.3.57

3.4 编写docker-compose.yml文件
cd /root/rocketmq
vim docker-compose.yml

输入内容:
version: '3'
services:
  #Service for nameserver
  namesrv:
    image: apacherocketmq/rocketmq(确认是否需要修改)
    container_name: rocketmq-namesrv
    ports:
      - 9876:9876
    environment:
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn256m
    volumes:
      - /root/rocketmq/data/namesrv/logs:/home/rocketmq/rocketmq-4.6.0/logs(确认是否需要修改)
    command: sh mqnamesrv

  #Service for broker
  broker:
    image: apacherocketmq/rocketmq(确认是否需要修改)
    container_name: rocketmq-broker
    links:
      - namesrv
    depends_on:
      - namesrv
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      - NAMESRV_ADDR=namesrv:9876
      - JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn256m
    volumes:
      - /root/rocketmq/data/broker/logs:/home/rocketmq/rocketmq-4.6.0/logs(确认是否需要修改)
      - /root/rocketmq/data/broker/store:/home/rocketmq/rocketmq-4.6.0/store(确认是否需要修改)
      - /root/rocketmq/etc/broker/broker.conf:/home/rocketmq/rocketmq-4.6.0/conf/broker.conf(确认是否需要修改)
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.6.0/conf/broker.conf(确认是否需要修改)

  #Service for rocketmq-dashboard
  dashboard:
    image: apacherocketmq/rocketmq-dashboard
    container_name: rocketmq-dashboard
    ports:
      - 8086:8080(确认是否需要修改)
    links:
      - namesrv
    depends_on:
      - namesrv
    environment:
      - NAMESRV_ADDR=namesrv:9876

3.5 启动和关闭
# 启动命令
cd /root/rocketmq
# 启动
docker-compose -f docker-compose.yml up
# 关闭
docker-compose -f docker-compose.yml down

当执行docker-compose启动命令成功后,可执行docker-compose关闭命令,但这个关闭命令会重新新建新的容器运行,之前的数据都会丢失;可通过docker stoprocketmq-namesrv rocketmq-broker rocketmq-dashboard命令逐一关闭相关容器,然后再通过docker start rocketmq-namesrv rocketmq-broker rocketmq-dashboard命令逐一启动相关容器

4、额外的docker命令,跟此次部署无关,仅做记录

# 查看某个镜像的latest的具体版本
docker image inspect apacherocketmq/rocketmq:latest|grep -i version
# 查看某个镜像的可挂载目录
docker inspect apacherocketmq/rocketmq|grep Volumes -C10

你可能感兴趣的:(mq,docker)