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

相关推荐
fo安方2 小时前
软考~系统规划与管理师考试——真题篇——章节——第5章 应用系统规划——解析版
java·运维·网络
qiuiuiu4132 小时前
正点原子RK3568学习日志21-实验1-字符设备点亮led
linux·学习
fai厅的秃头姐!2 小时前
01-python基础-day01Linux基础
linux
2501_945837432 小时前
零信任架构落地,云服务器全生命周期安全防护新体系
服务器
tianyuanwo2 小时前
Jenkins Job管理实战指南:增删改查与批量操作技巧
运维·jenkins
这儿有一堆花2 小时前
服务器安全:防火墙深度配置指南
服务器·安全·php
螺旋小蜗2 小时前
docker-compose文件属性(3)顶部元素networks
运维·docker·容器
无小道2 小时前
OS中的线程
linux·线程·进程·os·线程库·用户级线程库·线程使用
Q16849645152 小时前
红帽Linux-文件权限管理
linux·运维·服务器