docker-compose部署RocketMq

先看看官网:https://rocketmq.apache.org/zh/docs/4.x/quickstart/03quickstartWithDockercompose


尝试了在docker-compose文件中启动命令位置直接设置jvm内存大小,无法正常启动

command: sh mqbroker  -c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf Xms256m -Xmx256m

尝试在环境变量配置jvm内存

environment:
      - JAVA_OPTS= -Xmx256M -Xms256M -Xmn128M

依然无法正常运行,日志都无法正常查看

[root@lavm-wz4qbabjz9 mq]# docker logs d0
/home/rocketmq/rocketmq-4.9.6/bin/runbroker.sh: line 156:    27 Killed                  $JAVA ${JAVA_OPT} $@

最后想了个办法,先起个镜像,直接修改启动文件,然后打包为镜像

启动nameServer的mqnamesrv 是个脚本,它会使用runserver.sh启动,在runserver.sh中定义了Jvm内存参数

相同的启动borker的mqbroker脚本使用 runbroker.sh,可以修改其中的jvm参数

先拉取官方镜像:

docker pull apache/rocketmq:4.9.6

然后运行起来进入里面修改jvm参数后打包为镜像

docker run -id --name=myrocket apache/rocketmq:4.9.6

进入里面修改jvm参数

docker exec -it myrocket /bin/bash

使用vi 修改 runbroker.sh runserver.sh里的jvm内存配置后,打包容器为新镜像

docker commit myrocket myrocketmq:1.0

准备一个配置文件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.
brokerIP1=               # 测试了容器名,127.0.0.1,内网,都不行,外网ip可以
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable=true   #开启自动创建topic
enablePropertyFilter = true  #开启过滤

docker-compose.yml

version: '2.1'

services:
  namesrv:
    image: myrocketmq:1.0
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    networks:
      - rocketmq
    command: sh mqnamesrv

  broker:
    image: myrocketmq:1.0
    container_name: rmqbroker
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:
      - NAMESRV_ADDR=rmqnamesrv:9876
    volumes:
      - ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.conf
    depends_on:
      - namesrv
    networks:
      - rocketmq
    command: sh mqbroker  -c /home/rocketmq/rocketmq-4.9.6/conf/broker.conf

  dashboard:
    image: apacherocketmq/rocketmq-dashboard:latest
    container_name: dashboard
    ports:
      - 8080:8080
    environment:
      - JAVA_OPTS=-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Xms128m -Xmx256m
    networks:
      - rocketmq

networks:
  rocketmq:
    driver: bridge

开放端口9876,10911(borker的端口),10909(客户端查询具体的数据需要调用的端口,没找到如何设置环境变量,直接开放端口算了)

启动并后台运行

docker compose up -d

关闭并移出

docker compose down

关闭

docker compose stop

重启

docker compose restart
GitHub 加速计划 / compose / compose
33.27 K
5.15 K
下载
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。
最近提交(Master分支:2 个月前 )
501b5acd Add `jhrotko` to Core Maintainers. Signed-off-by: Laura Brehm <laurabrehm@hey.com> 9 天前
f51bc4cd Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> 9 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐