内网搭建阿里源的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

相关推荐
orion5713 小时前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站17 小时前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户1204872216119 小时前
Linux驱动编译与加载
linux·嵌入式
程序员老赵21 小时前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位21 小时前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术1 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
小猿姐1 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生