在国产ARM64环境下从源码编译Greptime DB及构建Docker镜像实践

背景

在国产化环境(KylinOS V10 SP2 + Kunpeng 920)部署 GreptimeDB 0.17.2 时,遇到了 jemalloc 内存分配错误:

复制代码
greptime            | <jemalloc>: Unsupported system page size
greptime            | <jemalloc>: Unsupported system page size
greptime            | <jemalloc>: Unsupported system page size
greptime            | memory allocation of 16 bytes failed

这个问题本质上是 ARM64 架构下内存页大小与默认 jemalloc 配置不匹配导致的。解决方案是从源码重新编译 Greptime DB 并构建适配的 Docker 镜像。

环境准备

1. Rust 环境配置

首先需要配置 Rust 工具链,使用国内镜像加速:

shell 复制代码
echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup' >> ~/.bashrc
echo 'export RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup' >> ~/.bashrc
source ~/.bashrc
# 安装 rust
curl --proto '=https' --tlsv1.2 -sSf https://mirrors.aliyun.com/repo/rust/rustup-init.sh | sh
source ~/.cargo/env

配置 Cargo 镜像源(~/.cargo/config.toml):

toml 复制代码
[source.crates-io]
replace-with = 'aliyun'
[source.aliyun]
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"
[net]
git-fetch-with-cli = true
[target.aarch64-unknown-linux-gnu]
linker = "clang"

2. 交叉编译工具链

shell 复制代码
# 临时切换为默认源,解决 loongarch64 下载问题
export RUSTUP_DIST_SERVER='https://static.rust-lang.org'
export RUSTUP_UPDATE_ROOT='https://static.rust-lang.org/rustup'
rustup toolchain install stable
rustup install nightly-2025-05-19
source ~/.bashrc
rustup target add aarch64-unknown-linux-gnu
cargo install cross
docker pull ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main

编译 GreptimeDB

关键步骤是设置正确的 jemalloc 页大小参数:

shell 复制代码
export JEMALLOC_SYS_WITH_LG_PAGE=16
cross build --release -F dashboard --target=aarch64-unknown-linux-gnu

前一步骤完成之后,会生成cross-custom-greptimedb:aarch64-unknown-linux-gnu-3e5a9-pre-build镜像,后续的编译在这个镜像中完成。

如果编译过程有中断,可以使用以下命令继续编译。

shell 复制代码
/usr/bin/docker run --userns host \
  -e JEMALLOC_SYS_WITH_LG_PAGE \
  -e 'PKG_CONFIG_ALLOW_CROSS=1' \
  -e 'XARGO_HOME=/xargo' \
  -e 'CARGO_HOME=/cargo' \
  -e 'CARGO_TARGET_DIR=/target' \
  -e 'CROSS_RUNNER=' \
  -e TERM \
  -e 'USER=root' \
  -e 'GITHUB_PROXY_URL=https://gh-proxy.org/https://github.com/' \
  -e 'CARGO_BUILD_JOBS=2' \
  -e 'CARGO_INCREMENTAL=0' \
  --rm --user 0:0 \
  -v /root/.xargo:/xargo:z \
  -v /root/.cargo:/cargo:z \
  -v /cargo/bin \
  -v /mnt/d/code/rust/greptimedb:/project:z \
  -v /root/.rustup/toolchains/nightly-2025-05-19-x86_64-unknown-linux-gnu:/rust:z,ro \
  -v /mnt/d/code/rust/greptimedb/target:/target:z \
  -w /project -i -t \
  cross-custom-greptimedb:aarch64-unknown-linux-gnu-3e5a9-pre-build \
  sh -c 'PATH=$PATH:/rust/bin cargo build --release -F dashboard --target=aarch64-unknown-linux-gnu'

构建 Docker 镜像

创建 Dockerfile:

dockerfile 复制代码
FROM ubuntu:22.04
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get \
    -y install ca-certificates curl && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
ADD greptime-0.17.2-linux-aarch64.tar.gz /
WORKDIR /greptime
ENV PATH /greptime/bin/:$PATH
ENV MALLOC_CONF="prof:true,prof_active:false"
ENTRYPOINT ["greptime"]

构建镜像:

shell 复制代码
docker build -t greptimedb:0.17.2-arm64 .

总结

在国产 ARM64 环境下部署 GreptimeDB 需要特别注意内存分配器的配置。通过从源码编译并设置正确的 jemalloc 参数,可以成功构建适配的 Docker 镜像。

相关推荐
Σίσυφος190023 分钟前
PCL法向量估计 之 方向约束法向量(Orientation Guided Normal)
数据库
老毛肚26 分钟前
手写mybatis
java·数据库·mybatis
海山数据库32 分钟前
移动云大云海山数据库(He3DB)postgresql_anonymizer插件原理介绍与安装
数据库·he3db·大云海山数据库·移动云数据库
云飞云共享云桌面35 分钟前
高性能图形工作站的资源如何共享给10个SolidWorks研发设计用
linux·运维·服务器·前端·网络·数据库·人工智能
2501_9279935343 分钟前
SQL Server 2022安装详细教程(图文详解,非常详细)
数据库·sqlserver
星火s漫天44 分钟前
第一篇: 使用Docker部署flask项目(Flask + DB 容器化)
数据库·docker·flask
xcLeigh1 小时前
Python 项目实战:用 Flask 实现 MySQL 数据库增删改查 API
数据库·python·mysql·flask·教程·python3
威迪斯特1 小时前
Flask:轻量级Web框架的技术本质与工程实践
前端·数据库·后端·python·flask·开发框架·核心架构
xu_yule1 小时前
Redis存储(15)Redis的应用_分布式锁_Lua脚本/Redlock算法
数据库·redis·分布式
一灰灰blog1 小时前
Spring AI中的多轮对话艺术:让大模型主动提问获取明确需求
数据库·人工智能·spring