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.0container_name: rmqnamesrvports:- 9876:9876networks:- rocketmqcommand: sh mqnamesrvbroker:image: myrocketmq:1.0container_name: rmqbrokerports:- 10909:10909- 10911:10911- 10912:10912environment:- NAMESRV_ADDR=rmqnamesrv:9876volumes:- ./broker.conf:/home/rocketmq/rocketmq-4.9.6/conf/broker.confdepends_on:- namesrvnetworks:- rocketmqcommand: sh mqbroker -c /home/rocketmq/rocketmq-4.9.6/conf/broker.confdashboard:image: apacherocketmq/rocketmq-dashboard:latestcontainer_name: dashboardports:- 8080:8080environment:- JAVA_OPTS=-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Xms128m -Xmx256mnetworks:- rocketmqnetworks:rocketmq:driver: bridge
开放端口9876,10911(borker的端口),10909(客户端查询具体的数据需要调用的端口,没找到如何设置环境变量,直接开放端口算了)
启动并后台运行
docker compose up -d
关闭并移出
docker compose down
关闭
docker compose stop
重启
docker compose restart