Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具(内网版)

前言

本节我们主要讲解下如何使用docker-compose一键式搭建一套RocketMQ的消息中间键集群服务,在项目开发中kafka与rockerMQ应该是我们最常用的消息中间键,为了最大化的利用系统资源,便于研究测试,docker容器搭建这些应用服务应该是我们的不二选择。

正文

  • 创建docker-compose的rocketmq.yml启动脚本
#rocketmq集群
version: '3.3'

services:
  rocketmq-namesrv-1:
    image: rocketmqinc/rocketmq-namesrv:4.5.0-alpine-uid
    container_name: rocketmq-namesrv-1
    ports:
      - 9876:9876
    volumes:
      - /usr/local/bin/atp/rocketmq/logs/nameserver1:/home/rocketmq/logs/rocketmqlogs
    command: sh mqnamesrv
    networks:
      - rocketmq

  rocketmq-namesrv-2:
    image: rocketmqinc/rocketmq-namesrv:4.5.0-alpine-uid
    container_name: rocketmq-namesrv-2
    ports:
      - 9877:9876
    volumes:
      - /usr/local/bin/atp/rocketmq/logs/nameserver2:/home/rocketmq/logs/rocketmqlogs
    command: sh mqnamesrv
    networks:
      - rocketmq
    
  rocketmq-broker-1:
    image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
    container_name: rocketmq-broker-1
    ports:
      - 10911:10911
    volumes:
      - /usr/local/bin/atp/rocketmq/logs/broker1:/home/rocketmq/logs/rocketmqlogs
      #- /usr/local/bin/atp/rocketmq/store/broker1:/home/rocketmq/store
      - /usr/local/bin/atp/rocketmq/conf/broker1/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
    depends_on:
      - rocketmq-namesrv-1
      - rocketmq-namesrv-2
    networks:
      - rocketmq
      
  rocketmq-broker-2:
    image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
    container_name: rocketmq-broker-2
    ports:
      - 10912:10911
    volumes:
      - /usr/local/bin/atp/rocketmq/logs/broker2:/home/rocketmq/logs/rocketmqlogs
      #- /usr/local/bin/atp/rocketmq/store/broker2:/home/rocketmq/store
      - /usr/local/bin/atp/rocketmq/conf/broker2/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
    depends_on:
      - rocketmq-namesrv-1
      - rocketmq-namesrv-2
    networks:
      - rocketmq
    
  rocketmq-broker-3:
    image: rocketmqinc/rocketmq-broker:4.5.0-alpine-uid
    container_name: rocketmq-broker-3
    ports:
      - 10913:10911
    volumes:
      - /usr/local/bin/atp/rocketmq/logs/broker3:/home/rocketmq/logs/rocketmqlogs
      #- /usr/local/bin/atp/rocketmq/store/broker3:/home/rocketmq/store
      - /usr/local/bin/atp/rocketmq/conf/broker3/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876"
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf autoCreateTopicEnable=true &
    depends_on:
      - rocketmq-namesrv-1
      - rocketmq-namesrv-2
    networks:
      - rocketmq
      
  rocketmq-console:
    image: styletang/rocketmq-console-ng
    container_name: rocketmq-console
    ports:
      - 9090:8080
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=rocketmq-namesrv-1:9876;rocketmq-namesrv-2:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      - rocketmq
    depends_on:
      - rocketmq-broker-1
      - rocketmq-broker-2
      - rocketmq-broker-3
          
networks:
  rocketmq:
    driver: bridge

Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具(内网版)_第1张图片

  • 创建broker服务器配置文件broker.conf
    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    #  Unless required by applicable law or agreed to in writing, software
    #  distributed under the License is distributed on an "AS IS" BASIS,
    #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #  See the License for the specific language governing permissions and
    #  limitations under the License.
    
    brokerClusterName = DefaultCluster
    #broker名称
    brokerName = rocketmq-broker-1
    brokerId = 0
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    

    本次我们搭建三台broker服务器,分别在宿主机卷映射目录下创建我们的配置文件

①/usr/local/bin/atp/rocketmq/conf/broker1/broker.conf

②/usr/local/bin/atp/rocketmq/conf/broker2/broker.conf

③/usr/local/bin/atp/rocketmq/conf/broker3/broker.conf

(1)创建配置文件目录,以broker1为例:

命令:mkdir -p /usr/local/bin/atp/rocketmq/conf/broker1

(2)使用vi编辑器创建broker配置文件broker.conf,只需更改服务器名称即可

Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具(内网版)_第2张图片

  • 启动集群

命令:docker-compose -f rocketmq.yml -p rocketmq up -d

Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具(内网版)_第3张图片

  • 验证集群

访问控制台:http//ip:9090

Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具(内网版)_第4张图片

结语

ok,关于Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具的内容到这里就结束啦,我们下期见。。。

你可能感兴趣的:(#,docker,#,docker-compose,#,MQ,docker,容器,mqtt,后端,分布式)