内网搭建阿里源的centos7系统源arm和x86

步骤 1:外网机器安装必备工具

联网安装同步工具和元数据生成工具

yum install -y yum-utils createrepo rsync

步骤 2:配置外网同步源(x86_64 + ARM 双架构)

创建两个 repo 文件,分别对应 x86_64 核心源和 aarch64 AltArch 源:

(1)配置 x86_64 架构阿里云源

bash

运行

cat > /etc/yum.repos.d/aliyun-centos7-x86_64.repo << 'EOF'

base-x86_64

name=CentOS-7 Base x86_64 - Aliyun

baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

updates-x86_64

name=CentOS-7 Updates x86_64 - Aliyun

baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

extras-x86_64

name=CentOS-7 Extras x86_64 - Aliyun

baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

epel-x86_64

name=EPEL-7 x86_64 - Aliyun

baseurl=https://mirrors.aliyun.com/epel/7/x86_64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

EOF

(2)配置 aarch64(ARM)架构阿里云 AltArch 源

bash

运行

cat > /etc/yum.repos.d/aliyun-centos7-aarch64.repo << 'EOF'

base-aarch64

name=CentOS-7 Base aarch64 - Aliyun AltArch

baseurl=https://mirrors.aliyun.com/centos-altarch/7/os/aarch64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7

updates-aarch64

name=CentOS-7 Updates aarch64 - Aliyun AltArch

baseurl=https://mirrors.aliyun.com/centos-altarch/7/updates/aarch64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7

extras-aarch64

name=CentOS-7 Extras aarch64 - Aliyun AltArch

baseurl=https://mirrors.aliyun.com/centos-altarch/7/extras/aarch64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7

epel-aarch64

name=EPEL-7 aarch64 - Aliyun

baseurl=https://mirrors.aliyun.com/epel/7/aarch64/

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

EOF

步骤 3:创建合并仓库目录结构(核心!)

按 "仓库类型→os→架构" 层级组织,确保双架构目录分离:

bash

运行

统一仓库根目录(后续拷贝到U盘)

mkdir -p /root/centos7-unified-repo

为每个仓库类型(base/updates/extras/epel)创建双架构目录

for repo in base updates extras epel; do

mkdir -p /root/centos7-unified-repo/${repo}/os/{x86_64,aarch64}

done

最终目录结构(关键,不能乱):

plaintext

centos7-unified-repo/

├─ base/os/

│ ├─ x86_64/ # x86_64架构base包

│ └─ aarch64/ # ARM架构base包

├─ updates/os/

│ ├─ x86_64/

│ └─ aarch64/

├─ extras/os/

│ ├─ x86_64/

│ └─ aarch64/

└─ epel/os/

├─ x86_64/

└─ aarch64/

步骤 4:同步 x86_64 架构包到对应目录(目录要一一对应)

bash

运行

同步x86_64的base仓库(-r指定repo ID,-p指定目标目录,-m保留元数据)

reposync -r base-x86_64 -p /root/centos7-unified-repo/base/os/ -m --arch=x86_64

同步x86_64的updates仓库

reposync -r updates-x86_64 -p /root/centos7-unified-repo/updates/os/ -m --arch=x86_64

同步x86_64的extras仓库

reposync -r extras-x86_64 -p /root/centos7-unified-repo/extras/os/ -m --arch=x86_64

同步x86_64的epel仓库

reposync -r epel-x86_64 -p /root/centos7-unified-repo/epel/os/ -m --arch=x86_64

首次同步约 20-25GB,耗时 1-2 小时(取决于网速)。
步骤 5:同步 aarch64(ARM)架构包到对应目录

bash

运行

同步ARM的base仓库(--arch指定aarch64架构)

reposync -r base-aarch64 -p /root/centos7-unified-repo/base/os/ -m --arch=aarch64

同步ARM的updates仓库

reposync -r updates-aarch64 -p /root/centos7-unified-repo/updates/os/ -m --arch=aarch64

同步ARM的extras仓库

reposync -r extras-aarch64 -p /root/centos7-unified-repo/extras/os/ -m --arch=aarch64

同步ARM的epel仓库(可选,包较少)

reposync -r epel-aarch64 -p /root/centos7-unified-repo/epel/os/ -m --arch=aarch64

ARM 架构总大小约 5-8GB,同步时间 30 分钟 - 1 小时。
步骤 6:为双架构分别生成元数据(必须!)一定要在外网生成,内网生成会报错

元数据是 yum 识别包的关键,需按架构单独生成,不能共用:

bash

运行

生成x86_64架构元数据(每个目录单独执行)

createrepo --update /root/centos7-unified-repo/base/os/x86_64/

createrepo --update /root/centos7-unified-repo/updates/os/x86_64/

createrepo --update /root/centos7-unified-repo/extras/os/x86_64/

createrepo --update /root/centos7-unified-repo/epel/os/x86_64/

生成aarch64架构元数据

createrepo --update /root/centos7-unified-repo/base/os/aarch64/

createrepo --update /root/centos7-unified-repo/updates/os/aarch64/

createrepo --update /root/centos7-unified-repo/extras/os/aarch64/

createrepo --update /root/centos7-unified-repo/epel/os/aarch64/

每个架构目录下会生成 repodata 文件夹,包含包索引和依赖信息。

步骤7:将centos7-unified-repo完整打包,传输到内网,可以用下面方法快速解压和切割

1. 使用 tar + pigz 进行并行压缩(推荐,速度快,支持多核)

tar -cf - /path/to/large/directory | pigz -p 8 > /backup/large_dir.tar.gz

2. 若需分卷(避免单文件过大,便于传输/存储)

tar -cf - /path/to/large/directory | pigz -p 8 | split -b 10G - /backup/large_dir.tar.gz.part_

步骤8:内网解压,通过nginx搭建centos7访问源

3. 恢复时合并并解压

cat /backup/large_dir.tar.gz.part_* | pigz -d | tar -xf -

nginx配置:百度一下就行

其他服务器yum配置:/etc/yum.repos.d/centos7.repo

local-centos7-base

name=Unified CentOS 7 Base ($basearch)

baseurl=http://192.168.1.1:8888/centos7/base/os/$basearch/

gpgcheck=0

gpgkey=http://192.168.1.1:8888/centos7/base/os/x86_64/RPM-GPG-KEY-CentOS-7

enabled=1

local-centos7-updates

name=Unified CentOS 7 Updates ($basearch)

baseurl=http://192.168.1.1:8888/centos7/updates/os/$basearch/

gpgcheck=0

gpgkey=http://192.168.1.1:8888/centos7/base/os/x86_64/RPM-GPG-KEY-CentOS-7

enabled=1

local-centos7-extras

name=Unified CentOS 7 Extras ($basearch)

baseurl=http://192.168.1.1:8888/centos7/extras/os/$basearch/

gpgcheck=0

gpgkey=http://192.168.1.1:8888/centos7/base/os/x86_64/RPM-GPG-KEY-CentOS-7

enabled=1

local-centos7-epel

name=Unified CentOS 7 EPEL ($basearch)

baseurl=http://192.168.1.1:8888/centos7/epel/os/$basearch/

gpgcheck=0

gpgkey=http://192.168.1.1:8888/centos7/epel/os/$basearch/RPM-GPG-KEY-EPEL-7

enabled=1

相关推荐
小康小小涵2 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
CQU_JIAKE2 小时前
4.28~4.30【Q】
linux·运维·服务器
左手厨刀右手茼蒿2 小时前
Linux 内核中的设备驱动开发:从字符设备到网络设备
linux·嵌入式·系统内核
先知后行。2 小时前
Linux 设备模型和platform平台
linux·运维·服务器
lzh200409192 小时前
深入理解进程:从PCB内核结构到写时拷贝的底层实战
linux·c++
Data_Journal2 小时前
如何使用cURL更改User Agent
大数据·服务器·前端·javascript·数据库
日取其半万世不竭3 小时前
Minecraft Java版社区服务器搭建教程(Linux,适合新手)
java·linux·服务器
时空自由民.3 小时前
蓝牙协议之GAP协议
linux·服务器·网络
byoass3 小时前
企业云盘与设计软件深度集成:AutoCAD/Revit/SolidWorks插件开发与API集成实战
服务器·网络·数据库·安全·oracle·云计算
leaves falling3 小时前
Linux 基础指令完全指南 —— 从入门到熟练
linux·运维·服务器