Docker compose安装apache MQ

一. 安装前准备:

  • 安装docker、docker Compose 环境
  • 关闭防火墙,关闭防火墙,关闭防火墙,重要的事情说三遍。

二.创建docker-compose.yml

version: "4.9.3"

services:
  rmqnamesrv:
    image: apache/rocketmq:latest
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    volumes:
      - /usr/local/rocketmq-docker/rmqs/logs:/opt/logs
      - /usr/local/rocketmq-docker/rmqs/store:/opt/store
    environment:
      JAVA_OPT_EXT: "-Duser.home=/opt -Xms512M -Xmx512M -Xmn128m"
    command: ["sh", "mqnamesrv"]
    networks:
      rmq:
        aliases:
          - rmqnamesrv
  rmqbroker:
    image: apache/rocketmq:latest
    container_name: rmqbroker
    ports:
      - 10909:10909
      - 10911:10911
    volumes:
      - /usr/local/rocketmq-docker/rmq/logs:/opt/logs
      - /usr/local/rocketmq-docker/rmq/store:/opt/store
      - /usr/local/rocketmq-docker/rmq/brokerconf/broker.conf:/etc/rocketmq/broker.conf
    environment:
      JAVA_OPT_EXT: "-Duser.home=/opt -Xms512M -Xmx512M -Xmn128m"
    command:
      [
        "sh",
        "mqbroker",
        "-c",
        "/etc/rocketmq/broker.conf",
        "-n",
        "172.16.50.112:9876",
        "autoCreateTopicEnable=true",
      ]
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqbroker

  rmqconsole:
    image: apacherocketmq/rocketmq-console:2.0.0
    container_name: rmqconsole
    ports:
      - 9080:8080
    environment:
      JAVA_OPTS: "-Drocketmq.namesrv.addr=172.16.50.112:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqconsole

networks:
  rmq:
    name: rmq
    driver: bridge

rocketmq  broker.conf配置文件如下:

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
#set `brokerIP1` if you want to set physical IP as broker IP.
#注意修改所在ip
brokerIP1= 172.16.50.112
#注意修改所在ip
namesrvAddr= 172.16.50.112:9876

三、执行脚本start.sh 

#分配权限
chmod -R 777 start.sh
#执行脚本
./start.sh

 如果失败,检查脚本start.sh 格式,

        设置::set ff=unix

#!/usr/bin/env bash

#创建目录
mkdir -p /usr/local/rocketmq-docker/rmqs/logs
mkdir -p /usr/local/rocketmq-docker/rmqs/store
mkdir -p /usr/local/rocketmq-docker/rmq/logs
mkdir -p /usr/local/rocketmq-docker/rmq/store
mkdir -p /usr/local/rocketmq-docker/rmq/brokerconf
#设置目录权限
chmod -R 777 /usr/local/rocketmq-docker/rmqs/logs
chmod -R 777 /usr/local/rocketmq-docker/rmqs/store
chmod -R 777 /usr/local/rocketmq-docker/rmq/logs
chmod -R 777 /usr/local/rocketmq-docker/rmq/store

#rocketmq broker配置文件
cp broker.conf /usr/local/rocketmq-docker/rmq/brokerconf
chmod -R 777 /usr/local/rocketmq-docker/rmq/brokerconf/broker.conf

#关闭防火墙
service iptables stop
chkconfig iptables off
systemctl restart docker

#显示 rocketmq容器
docker ps |grep rocketmq


#下载并启动容器,切为 后台 自动启动
docker-compose up -d

注意:

  • 把broker.conf 、docker-compose.yml、rocket-start.sh放在同一目录启动完成后,打开:
http://172.16.50.112:9080/#/

Docker compose安装apache MQ_第1张图片

四. 常见问题

1.rocketmq console 页面打开提示:

2.console日志:java.lang.RuntimeException: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to <10.16.100.41:10909> failed

Docker compose安装apache MQ_第2张图片

  •  关闭防火墙,关闭防火墙,关闭防火墙,重要的事情说三遍。
  • 检查broker.conf,

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