arm64环境部署rocketmq(x86架构同理)
1. 编译rocketmq镜像
拉取代码
git clone https://github.com/apache/rocketmq-docker.git
安装docker-compose
略
编译镜像
进入image-build目录
cd rocketmq-docker/image-build
修改arm环境支持的基础镜像
vim Dockerfile-alpine
将原来的eclipse-temurin:8-jdk-alpine替换为arm环境支持的openjdk就行,镜像从网上找
执行命令
sh build-image.sh 4.9.2 alpine
注:我当时打镜像的时候报错uid和gid的问题,因为Dockerfile里的uid和gid用的是变量,我是直接替换为固定3000了,没有用到它定义的变量
镜像完成后查看镜像
root@chaoyue:~/lzy/rocketmq-docker-master# docker images|grep rocket
apache/rocketmq 4.9.2-alpine 7414c51d2dcb 2 hours ago 178MB
2. 创建持久化目录
mkdir rocketmq
cd rocketmq
mkdir -p data/broker/conf data/broker/logs data/broker/store namesrv
赋予777的权限
chmod -R 777 data
3. 创建启动脚本
cat data/broker/runbroker.sh
#!/bin/bash
# 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.
#===========================================================================================
# Java Environment Setting
#===========================================================================================
error_exit() {
echo "ERROR: $1 !!"
exit 1
}
find_java_home() {
case "$(uname)" in
Darwin)
JAVA_HOME=$(/usr/libexec/java_home)
;;
*)
JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
;;
esac
}
find_java_home
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
export JAVA_HOME
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=$(dirname $0)/..
export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
#===========================================================================================
# JVM Configuration
#===========================================================================================
calculate_heap_sizes() {
case "$(uname)" in
Linux)
system_memory_in_mb=$(free -m | sed -n '2p' | awk '{print $2}')
system_cpu_cores=$(egrep -c 'processor([[:space:]]+):.*' /proc/cpuinfo)
;;
FreeBSD)
system_memory_in_bytes=$(sysctl hw.physmem | awk '{print $2}')
system_memory_in_mb=$(expr $system_memory_in_bytes / 1024 / 1024)
system_cpu_cores=$(sysctl hw.ncpu | awk '{print $2}')
;;
SunOS)
system_memory_in_mb=$(prtconf | awk '/Memory size:/ {print $3}')
system_cpu_cores=$(psrinfo | wc -l)
;;
Darwin)
system_memory_in_bytes=$(sysctl hw.memsize | awk '{print $2}')
system_memory_in_mb=$(expr $system_memory_in_bytes / 1024 / 1024)
system_cpu_cores=$(sysctl hw.ncpu | awk '{print $2}')
;;
*)
# assume reasonable defaults for e.g. a modern desktop or
# cheap server
system_memory_in_mb="2048"
system_cpu_cores="2"
;;
esac
# some systems like the raspberry pi don't report cores, use at least 1
if [ "$system_cpu_cores" -lt "1" ]; then
system_cpu_cores="1"
fi
# set max heap size based on the following
# max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))
# calculate 1/2 ram and cap to 1024MB
# calculate 1/4 ram and cap to 8192MB
# pick the max
half_system_memory_in_mb=$(expr $system_memory_in_mb / 2)
quarter_system_memory_in_mb=$(expr $half_system_memory_in_mb / 2)
if [ "$half_system_memory_in_mb" -gt "1024" ]; then
half_system_memory_in_mb="1024"
fi
if [ "$quarter_system_memory_in_mb" -gt "8192" ]; then
quarter_system_memory_in_mb="8192"
fi
if [ "$half_system_memory_in_mb" -gt "$quarter_system_memory_in_mb" ]; then
max_heap_size_in_mb="$half_system_memory_in_mb"
else
max_heap_size_in_mb="$quarter_system_memory_in_mb"
fi
MAX_HEAP_SIZE="${max_heap_size_in_mb}M"
# Young gen: min(max_sensible_per_modern_cpu_core * num_cores, 1/4 * heap size)
max_sensible_yg_per_core_in_mb="100"
max_sensible_yg_in_mb=$(expr $max_sensible_yg_per_core_in_mb "*" $system_cpu_cores)
desired_yg_in_mb=$(expr $max_heap_size_in_mb / 4)
if [ "$desired_yg_in_mb" -gt "$max_sensible_yg_in_mb" ]; then
HEAP_NEWSIZE="${max_sensible_yg_in_mb}M"
else
HEAP_NEWSIZE="${desired_yg_in_mb}M"
fi
}
calculate_heap_sizes
# Dynamically calculate parameters, for reference.
Xms=$MAX_HEAP_SIZE
Xmx=$MAX_HEAP_SIZE
Xmn=$HEAP_NEWSIZE
MaxDirectMemorySize=$MAX_HEAP_SIZE
# Set for `JAVA_OPT`.
JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=${MaxDirectMemorySize}"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
JAVA_OPT="${JAVA_OPT} -Drocketmq.broker.diskSpaceWarningLevelRatio=0.99"
numactl --interleave=all pwd >/dev/null 2>&1
if [ $? -eq 0 ]; then
if [ -z "$RMQ_NUMA_NODE" ]; then
numactl --interleave=all $JAVA ${JAVA_OPT} $@
else
numactl --cpunodebind=$RMQ_NUMA_NODE --membind=$RMQ_NUMA_NODE $JAVA ${JAVA_OPT} $@
fi
else
$JAVA ${JAVA_OPT} $@
fi
4. 编辑docker-compose文件
cat docker-compose.yml
version: '3'
services:
namesrv:
image: apache/rocketmq:4.9.2-alpine
container_name: rmqnamesrv
ports:
- 9876:9876
environment:
- NAMESRV_ADDR=namesrv:9876
volumes:
- ./data/namesrv/logs:/home/rocketmq/logs
command: sh mqnamesrv
restart: always
broker:
image: apache/rocketmq:4.9.2-alpine
container_name: rmqbroker
privileged: true
links:
- namesrv
ports:
- 10909:10909
- 10911:10911
- 10912:10912
environment:
- NAMESRV_ADDR=namesrv:9876
volumes:
- ./data/broker/logs:/home/rocketmq/logs
- ./data/broker/store:/home/rocketmq/store
- ./data/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.9.2/conf/broker.conf
- ./data/broker/runbroker.sh:/home/rocketmq/rocketmq-4.9.2/bin/runbroker.sh
command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.2/conf/broker.conf
depends_on:
- namesrv
restart: always
rmqconsole:
image: candice0630/rocketmq-console-ng:2.0
container_name: rmqconsole
ports:
- 9001:8080
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=namesrv:9876
-Dcom.rocketmq.sendMessageWithVIPChannel=false
depends_on:
- namesrv
restart: always
5. 编辑配置文件
cat data/broker/conf/broker.conf
brokerIP1 = 192.168.31.28
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
diskMaxUsedSpaceRatio=99
注:IP改成你自己的服务器IP
6. 下载镜像
如果arm服务器可以拉取外网镜像,那就直接拉取
docker pull candice0630/rocketmq-console-ng:2.0
如果arm机器没有办法拉取镜像,那就找一台x86的机器也可以拉取arm镜像
配置方法:点击查看:x86平台拉取arm64平台镜像
docker pull --platform arm64 candice0630/rocketmq-console-ng:2.0
7. 启动rocketmq
docker-compose up -d
8. 测试
通过rmqconsole测试
访问http://localhost:9001/#/topic
有一条测试topic,点击SEND_MESSAGE
,随便填写,点击提交,出现SEND_OK
说明发送成功,可以通过消息tab,选择测试topic搜索来查看刚发送的消息。
通过命令行测试
进入容器执行
./tools.sh org.apache.rocketmq.example.quickstart.Producer
这条命令会发送一批测试消息
结果:
SendResult [sendStatus=SEND_OK, msgId=7F00000100A054BEDEF26E08E3CE03E7, offsetMsgId=C0A81F1C00002A9F000000000002ED99, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=3], queueOffset=249]
执行获取消息
./tools.sh org.apache.rocketmq.example.quickstart.Consumer
标签:OPT,JAVA,mb,部署,system,arm64,memory,rocketmq
From: https://blog.csdn.net/qq_54738879/article/details/140614216