Skip to content

什么是源

首先,来看一下什么是“源”。在Linux中,“源”(或“软件源”)指的是软件包管理器获取软件包和更新的位置。它是一个包含软件包信息的服务器或镜像站点,允许你通过软件包管理器下载安装软件、更新系统和安装程序所需的依赖关系。

软件源存储着软件包的元数据信息,如软件包名称、版本、依赖关系等。当你使用包管理器(如apt、yum、pacman等)来安装新软件、更新系统或查找可用软件包时,系统会访问这些软件源以获取所需信息。


.repo 文件

  • [repo_name]:仓库的名称,通常是该源的标识符。
  • name:仓库的描述名称,用于表示该仓库的目的。
  • baseurl:仓库的 URL 地址,指向 RPM 包所在的目录。它可以是 HTTP、FTP 或本地文件路径(例如 file:///path/to/repo/)。
  • enabled:是否启用该仓库,1 表示启用,0 表示禁用。
  • gpgcheck:是否检查 GPG 签名,1 表示启用签名检查,0 表示不检查。
  • gpgkey:用于验证软件包签名的 GPG 公钥 URL。

yum 优先级

YUM 源的优先级可以通过 yum-plugin-priorities 插件来设置。如果多个仓库提供相同的软件包,YUM 会优先选择优先级较高的仓库。

安装插件

bash
yum install yum-plugin-priorities

在 .repo 文件中设置优先级

bash
[repo_name] priorities=10

NOTE

优先级数值越小,优先级越高。priority 数值范围是 1 到 99。


国内镜像站

阿里云

官网地址:https://developer.aliyun.com/mirror/

华为云

官网地址:https://mirrors.huaweicloud.com/home

腾讯云

官网地址:https://mirrors.tencent.com/#/index

openEuler

openEuler官方地址:https://openeuler.org/

openEuler Repo:https://dl-cdn.openeuler.openatom.cn/

清华大学

官网地址:https://mirrors.tuna.tsinghua.edu.cn/

网易

官网地址:http://mirrors.163.com/


CentOS/RHEL系列

仓库配置文件在/etc/yum.repos.d/目录下

NOTE

通知:CentOS 8操作系统版本结束了生命周期(EOL),Linux社区已不再维护该操作系统版本。建议您使用openEuler

备份源文件

bash
# 创建备份目录
mkdir /etc/yum.repos.d/bak
# 旧源源文件移动到bak中并标识今日日期
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/bak/CentOS-Base-$(date +%F).repo

阿里云

CentOS 8

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

CentOS 7

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

CentOS 6

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

基础仓库 (Base):

bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
mirrorlist=https://mirrors.aliyun.com/repo/Centos-$releasever/base/

更新仓库 (Updates):

bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
mirrorlist=https://mirrors.aliyun.com/repo/Centos-$releasever/updates/

额外仓库 (Extras):

bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
mirrorlist=https://mirrors.aliyun.com/repo/Centos-$releasever/extras/

华为云

CentOS 8

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-8-anon.repo

CentOS 7

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo

基础仓库 (Base)

bash
baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/

更新仓库 (Updates)

bash
baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/

额外仓库 (Extras)

bash
baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/

清华大学

CentOS 8

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-8.repo

CentOS 7

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/repo/Centos-7.repo

基础仓库 (Base)

bash
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/

更新仓库 (Updates)

bash
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/

额外仓库 (Extras)

bash
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/

网易源

CentOS 7

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

CentOS 6

bash
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo

腾讯云

一键配置

bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos7_base.repo

基础仓库 (Base)

bash
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch/

更新仓库 (Updates)

bash
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/updates/$basearch/

额外仓库 (Extras)

bash
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch/

清除缓存

CentOS8以上使用dnf

bash
yum clean all

生成缓存

CentOS8以上使用dnf

bash
yum makecache

验证新源是否可用

bash
yum repolist

Debian/Ubuntu系列

仓库配置文件在/etc/apt/sources.list

备份源文件

bash
# 创建备份目录
mkdir /etc/apt/bak
# 旧源源文件移动到bak中并标识今日日期
mv /etc/apt/sources.list /etc/apt/bak/sources-$(date +%F).list

查看系统版本

获取Ubuntu系统发布版本的代号,不同发布版本代号不同,配置也是不同的

bash
lsb_release -a
# 或
cat /etc/os-release

阿里云

下载地址: https://mirrors.aliyun.com/ubuntu/

ubuntu 14.04 LTS (trusty) (EOL)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

## Not recommended
# deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
EOF

ubuntu 16.04 LTS (xenial) (EOL)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ xenial main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial main

deb https://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb https://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial universe
deb https://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb https://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security universe
EOF

ubuntu 18.04 LTS (bionic)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

EOF

ubuntu 20.04 LTS (focal)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

EOF

ubuntu 22.04 LTS (jammy)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

EOF

ubuntu 23.04 (lunar)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse

EOF

ubuntu 24.04 (noble)

bash
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse

EOF

华为云

Linux发行版 x86

bash
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.huaweicloud.com@g" /etc/apt/sources.list

Arm64,Armhf

替换源文件域名

bash
sudo sed -i "s@http://ports.ubuntu.com@https://repo.huaweicloud.com@g" /etc/apt/sources.lis

选择相应list文件

到官网上选择对应的list文件获取下载链接命令:https://mirrors.huaweicloud.com/mirrorDetail/5ea14dfd22e76b8dea9ab0e8

bash
wget -O /etc/apt/sources.list https://mirrors.huaweicloud.com/repository/conf/Ubuntu-Ports-bionic.list

清华大学

Ubuntu 24.04 LTS (noble)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse

Ubuntu 24.10 LTS (roacular)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ oracular-proposed main restricted universe multiverse

Ubuntu 22.04 LTS (jammy)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

Ubuntu 20.04 LTS (focal)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

Ubuntu 18.04 LTS (bionic)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

Ubuntu 16.04 LTS (xenial) (EOL)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

Ubuntu 14.04 LTS (trusty) (EOL)

bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse

更新索引

bash
apt update
# 旧版使用apt-get
apt-get update

openEuler

官网repo地址:https://dl-cdn.openeuler.openatom.cn/

选择openEuler 版本及系统架构选择配置内容:https://mirrors.huaweicloud.com/mirrorDetail/5ebe3408c8ac54047fe607f0

bash
cat > openEuler.repo << EOF
[openEuler-everything]
name=openEuler-everything
baseurl=https://mirrors.huaweicloud.com/openeuler/openEuler-24.03-LTS/everything/x86_64/
enabled=1
gpgcheck=0
gpgkey=https://mirrors.huaweicloud.com/openeuler/openEuler-24.03-LTS/everything/x86_64/RPM-GPG-KEY-openEuler
        
[openEuler-EPOL]
name=openEuler-epol
baseurl=https://mirrors.huaweicloud.com/openeuler/openEuler-24.03-LTS/EPOL/main/x86_64/
enabled=1
gpgcheck=0

[openEuler-update]
name=openEuler-update
baseurl=https://mirrors.huaweicloud.com/openeuler/openEuler-24.03-LTS/update/x86_64/
enabled=1
gpgcheck=0
EOF

光盘挂载

sr0 和 cdrom

  • /dev/sr0是光驱的设备名;
  • /dev/cdrom代表光驱;

cdrom 只是 sr0 的软链接。

创建挂载目录

bash
mkdir /media/cdrom

挂载镜像

bash
mount /dev/cdrom /media/cdrom

验证

bash
df -hT /media/cdrom

修改配置文件

bash
# 进入yum仓库指定目录
cd /etc/yum.repos.d
# 备份旧源
mkdir bak && mv ./* bak

cat > media.repo << EOF
[media]
name=openEuler-$releasever-media
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
EOF

更新 YUM 缓存

bash
yum clean all && yum makecache

设置开机自动挂载

编辑 /etc/fstab 文件:

bash
vim /etc/fstab

# 添加如下
/dev/sr0 /media/cdrom iso9660 defaults,user,ro 0 0

ISO挂载

创建挂载目录

bash
mkdir /media/iso

下载iso文件

bash
# 创建存储目录
mkdir /data/iso

# 下载镜像文件
wget https://repo.openeuler.org/openEuler-24.03-LTS/ISO/x86_64/openEuler-24.03-LTS-x86_64-dvd.iso

挂载ISO文件

找到您的 ISO 文件。例如,假设您的 ISO 文件名为 openEuler-24.03-LTS-x86_64-dvd.iso,并且它位于 /data/iso 目录中

bash
mount -o loop /data/iso/openEuler-24.03-LTS-x86_64-dvd.iso /media/iso

-o loop 表示使用循环设备挂载镜像文件

验证

bash
df -hT /media/iso

修改配置文件

bash
# 进入yum仓库指定目录
cd /etc/yum.repos.d
# 备份旧源
mkdir bak && mv ./* bak

cat > iso.repo << EOF
[iso]
name=openEuler-$releasever-iso
baseurl=file:///media/iso
enabled=1
gpgcheck=0
EOF

更新 YUM 缓存

bash
yum clean all && sudo yum makecache

‌设置开机自动挂载

编辑 /etc/fstab 文件,添加如下行(替换实际 ISO 路径)

bash
/data/iso/openEuler-24.03-LTS-x86_64-dvd.iso /media/iso iso9660 loop,ro,nosuid,nodev,noexec 0 0

保存后执行 mount -a 重新加载配置

RHEL 8+ 本地挂载

适用于Rocky Linux 或 AlmaLinux,主要区别在于AppStreamAppStream目录,AppStream和BaseOS两个目录之间的关系是互补的。

  • AppStream:AppStream目录存储着应用程序和软件包的元数据信息,以及软件包依赖关系等。这个目录包含用户可能需要的各种应用程序、工具和其他软件包,使用户可以方便地安装和管理这些软件。AppStream目录通常包含用户界面软件、开发工具、数据库工具等应用程序。

  • BaseOS:BaseOS目录存储着操作系统的核心组件和基本系统工具。如内核、shell工具、系统服务等。

创建挂载目录

bash
mkdir /media/cdrom

挂载镜像

bash
mount /dev/cdrom /media/cdrom

验证

bash
df -hT /media/cdrom

修改配置文件

bash
# Media.repo

[media-baseos]
name=RHEL8-Linux$releasever-Media-BaseOS
baseurl=file:///media/cdrom/BaseOS
gpgcheck=0
enabled=1

[media-appstream]
name=RHEL8-Linux-$releasever-Media-AppStream
baseurl=file:///media/cdrom/AppStream
gpgcheck=0
enabled=1

更新 YUM 缓存

bash
yum clean all && yum makecache

设置开机自动挂载

编辑 /etc/fstab 文件:

bash
vim /etc/fstab

# 添加如下
/dev/sr0 /media/cdrom iso9660 defaults,user,ro 0 0

私有仓库搭建

修改YUM配置文件(启用缓存)

ini
# 编辑主配置文件
# vim /etc/yum.conf
# 缓存路径(默认无需修改)
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1

使用YUM安装软件包(触发缓存)

bash
yum install -y package_name  # 安装任意软件包(如httpd)
  • 缓存文件会自动保存到 /var/cache/yum/ 下对应子目录

收集缓存的RPM包到指定路径

bash
# 创建目标目录
mkdir -p /data/rpm
# 复制所有缓存的RPM包
find /var/cache/yum/ -type f -name "*.rpm" -exec cp {} /data/rpm \;
  • 注意:若系统使用dnf,路径可能为 /var/cache/dnf/

生成YUM仓库元数据

bash
dnf -y install createrepo
# 生成repodata目录
createrepo -v /data/rpm

安装服务httpd

bash
dnf -y install httpd
# 修改配置文件
# 打开注释
ServerName ...
# 修改业务路径
# 找到 DocumentRoot "/var/www/html" 这一段   //apache的根目录
# 把/var/www/html 这个目录改到 /data/rpm

systemctl enable httpd --now

客户端配置本地YUM源

bash
# 创建YUM源配置文件
cat > /etc/yum.repos.d/local.repo <<EOF
[local-rpm]
name=Local RPM Repository
baseurl=file:///opt/rpm        # 或使用HTTP路径(如http://your_ip/rpm)
enabled=1
gpgcheck=0
EOF

# 清除并重建缓存
dnf clean all
dnf makecache