rocketmq容器化部署

1.1. 创建数据目录

mkdir -p /data/rocketmq/{broker,dashboard,namesrv}
cd /data/rocketmq/broker
mkdir conf logs store
cd /data/rocketmq/namesrv
mkdir logs

1.2. 准备配置文件

在部署过程中,共需要准备三个配置文件,分别是broker.confplain_acl.ymlusers.properties

  • broker.conf是broker的配置文件,可以从apache/rocketmq:5.1.3镜像中copy出原始版本进行修改。路径是:/data/rocketmq/broker/conf/broker.conf。主要内容如下:

brokerClusterName = DefaultCluster
brokerName = broker-1
brokerId = 0
deleteWhen = 04
fileReservedTime = 72
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 是否允许Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
# 是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
# 开启ACL权限控制
aclEnable=true
brokerIP1 = 192.168.10.111

plain_acl.yml是acl权限控制配置文件,可以从apache/rocketmq:5.1.3镜像中copy出原始版本进行修改。该配置文件主要是设置用户、密码、权限、白名单等配置。路径是:/data/rocketmq/broker/conf/plain_acl.yml。主要内容如下:

# 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.

globalWhiteRemoteAddresses:

accounts:
  - accessKey: RocketMQ
    secretKey: 12345678
    whiteRemoteAddress:
    admin: false
    defaultTopicPerm: DENY
    defaultGroupPerm: SUB
    topicPerms:
      - topicA=DENY
      - topicB=PUB|SUB
      - topicC=SUB
    groupPerms:
      # the group should convert to retry topic
      - groupA=DENY
      - groupB=PUB|SUB
      - groupC=SUB

  - accessKey: rocketmq2
    secretKey: 12345678
    whiteRemoteAddress: 
    # if it is admin, it could access all resources
    admin: true

users.properties是设置rocketmq-dashboard面板身份认证的配置文件。路径是:/data/rocketmq/dashboard/users.properties。其主要配置内容如下:

# 该文件支持热修改,即添加和修改用户时,不需要重新启动console
# 格式, 每行定义一个用户, username=password[,N]  #N是可选项,可以为0 (普通用户); 1 (管理员)  

#定义管理员 
admin=Admin123,1

#定义普通用户
#user1=user1
#user2=user2

1.3. 容器编排

在数据目录/data/rocketmq目录中创建docker-compose.yaml文件,内容如下:

version: '3.3'
services:
  namesrv:
    image: apache/rocketmq:5.1.3
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    environment:
      JAVA_OPT_EXT: "-server -Xms512m -Xmx512m"
    volumes:
      - /data/rocketmq/namesrv/logs:/home/rocketmq/logs
    command: sh mqnamesrv
    restart: always
  broker1:
    image: apache/rocketmq:5.1.3
    container_name: rmqbroker
    links:
      - namesrv
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      NAMESRV_ADDR: namesrv:9876
      JAVA_OPT_EXT: "-server -Xms512m -Xmx512m"
    volumes:
      - /data/rocketmq/broker/logs:/home/rocketmq/logs
      - /data/rocketmq/broker/store:/home/rocketmq/store
      - /data/rocketmq/broker/conf/broker.conf:/home/rocketmq/rocketmq-5.1.3/conf/broker.conf
      - /data/rocketmq/broker/conf/plain_acl.yml:/home/rocketmq/rocketmq-5.1.3/conf/plain_acl.yml
    command: sh mqbroker -c /home/rocketmq/rocketmq-5.1.3/conf/broker.conf
    restart: always
  dashbord:
    image: apacherocketmq/rocketmq-dashboard:1.0.0
    container_name: rmqdashbord
    volumes:
      - /data/rocketmq/dashboard:/tmp/rocketmq-console/data
    ports:
      - 28080:8080
    environment:
      JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.loginRequired=true -Drocketmq.config.accessKey=rocketmq2 -Drocketmq.config.secretKey=12345678"
    restart: always

1.4. 启动

cd /data/rocketmq
docker-compose up -d

你可能感兴趣的:(java-rocketmq,rocketmq,java)