首页 > 其他分享 >arm64环境部署rocketmq

arm64环境部署rocketmq

时间:2024-07-22 17:27:34浏览次数:15  
标签:OPT JAVA mb 部署 system arm64 memory rocketmq

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

相关文章

  • 如何攻克LLM应用的调试?教你本地化部署与使用一款免费的LLM应用工程化平台
    随着LLM应用的不断成熟,特别是在B端企业场景中的逐渐落地,其不再停留在原型与验证阶段,将面临着更高的工程化要求,无论是输出的稳定性、性能、以及成本控制等,都需要实现真正的“生产就绪”;但由于大量的应用基于LangChain、LlamaIndex等框架开发,更多的抽象与封装使得应用难以跟踪......
  • RocketMQ
    Docker容器部署version:'3'services:namesrv:image:apache/rocketmq:latestcontainer_name:rmqnamesrvports:-9876:9876networks:-rocketmqcommand:shmqnamesrvbroker:image:apache/rocketmq:latestc......
  • UOS系统部署KingbaseES V8R6 java故障“InvocationTargetException”
    案例说明:在UOS系统下部署KingbaseESV8R6数据库时,出现Java错误,部署失败。系统版本:kingbase@srv01:~$cat/etc/os-releasePRETTY_NAME="UnionTechOSServer20"NAME="UnionTechOSServer20"VERSION_ID="20"VERSION="20"ID=UOSHOME_URL="h......
  • Linux下MySQL的安装部署
    文章目录前言一、MySQL是什么?二、MySQL安装部署(两种)1.手动安装MySQL(1)下载MySQL安装包(2)解压压缩包至opt文件夹下(3)重命名mysql-8.0.33-linux-glibc2.12-x86_64文件夹(4)创建用户组和密码(5)为mysql用户授权(6)创建数据文件的存储位置(7)初始化MySQL数据库(8)编辑MySQL的配置文件(9)......
  • Linux 部署DVWA靶场
    Linux部署DVWA靶场DVWA是一款开源的网络安全漏洞实践平台,专为安全学习者设计。它涵盖了XXS、SQL注入、文件上传、文件包含、CSRF和暴力破解等多种安全漏洞环境,每个漏洞都有从简单到复杂的多个难度级别。环境部署安装httpd及其相关的组件yuminstall-yhttpdhttpd-devel......
  • PyCharm远程部署带屏幕影响串口
    我有一个Flaskapp.py,我正在本地计算机上开发。Flask应用程序使用连接到远程计算机的串行接口(pyserial)。我设置PyCharm以在远程计算机上进行远程部署机器。当我远程(从本地机器)部署和运行应用程序时,我想在独立的screen中启动它,以便我可以在需......
  • 如何在 vercel 部署中路由 python 和 typescript 无服务器函数
    我从一个带有Next.js和Typescript前端以及python后端的全栈应用程序开始。由于我们想在vercel上部署,因此我们将所有后端功能迁移到/api文件夹中的typescript函数中,可通过以下方式访问:fetch('api/**foldername**)问题是我有一个简单的pytorch模型,因此......
  • docker-compose部署kafka-ui部署以及使用
    1.docker-compose配置脚本version:"3"services:kafka-ui:image:provectuslabs/kafka-ui:v0.7.2container_name:kafka-uihostname:kafka-uiprivileged:truerestart:alwaysenvironment:-DYNAMIC_CONFIG_ENABLED=true......
  • Linux 下部署 syncthing 中继服务器
    来自......
  • MSSQL sqli labs部署
    MSSQLsqlilabs部署1.用Win11自带的iis搭建asp网站打开控制面板中的程序部分,点击启用或关闭Windows功能勾选如图选项加载完毕后按win键打开iis打开asp,将启用父路径改为True右键添加网站网站名称可随意写,物理路径改到保存的MSSQLsqlilabs文件夹(有asp文件的文件夹......