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

相关推荐
2401_8346369920 分钟前
Nginx 从入门到实战:静态 / 动态站点、PHP 部署与反向代理全解析
运维·nginx·php
爱喝水的鱼丶26 分钟前
SAP-ABAP:SAP视图开发入门:四类标准视图的适用场景与创建步骤详解
服务器·数据库·性能优化·sap·abap
aosky1 小时前
一台电脑配置多个 SSH Key 对应不同的 GitHub 账号
运维·ssh·github
云登指纹浏览器2 小时前
WebDriver反检测技术详解:如何让自动化脚本看起来像真实浏览器
运维·自动化·跨境电商
xmtxz2 小时前
计算机网络基础课程学习心得:从理论抽象到硬核实战的进阶之路
运维·学习
凡人叶枫2 小时前
Effective C++ 条款17:以独立语句将 newed 对象置入智能指针
java·linux·开发语言·c++·算法
RisunJan3 小时前
Linux命令-pgrep (通过进程名查找进程 ID)
linux·运维
回忆2012初秋3 小时前
【Nginx】优雅地走进高性能 Web 服务器世界(1)
服务器·前端·nginx
信创工程师-小杨3 小时前
Linux内网环境如何解决依赖的问题
linux·运维·服务器
设计师小聂!3 小时前
宝塔 Linux 面板保姆级教程
linux·mysql·开源·运维开发