Centos 9 镜像源
适用于 CentOS 9 Stream 的完整镜像源配置。CentOS 9 Stream 使用 dnf
包管理器来安装和更新软件包。你需要编辑或创建 /etc/yum.repos.d/CentOS-Stream.repo
文件来配置你的镜像源。
完整的 CentOS 9 Stream 镜像源配置
方法一:使用阿里云镜像源
阿里云提供了快速稳定的镜像源,以下是配置文件的内容:
# CentOS-Stream.repo
#
# The mirror system uses the connecting IP address of the client and the update status of each mirror to pick mirrors that are updated to date and close to the client. You should use this for CentOS updates unless you are manually picking other mirrors.
#
#
[baseos]
name=CentOS Stream $releasever - BaseOS
baseurl=http://mirrors.aliyun.com/centos/$releasever-stream/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-centosofficial
[appstream]
name=CentOS Stream $releasever - AppStream
baseurl=http://mirrors.aliyun.com/centos/$releasever-stream/AppStream/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-centosofficial
[extras]
name=CentOS Stream $releasever - Extras
baseurl=http://mirrors.aliyun.com/centos/$releasever-stream/extras/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-centosofficial
[powertools]
name=CentOS Stream $releasever - PowerTools
baseurl=http://mirrors.aliyun.com/centos/$releasever-stream/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-centosofficial
方法二:使用其他常用镜像源
如果你更倾向于使用其他镜像源,如清华大学开源软件镜像站、网易等,可以参考以下配置:
清华大学镜像源
[baseos]
name=CentOS Stream $releasever - BaseOS - Tsinghua
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever.2-stream/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-Official
[appstream]
name=CentOS Stream $releasever - AppStream - Tsinghua
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever.2-stream/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-Official
[extras]
name=CentOS Stream $releasever - Extras - Tsinghua
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever.2-stream/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-Official
[powertools]
name=CentOS Stream $releasever - PowerTools - Tsinghua
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever.2-stream/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-Official
请注意,对于清华大学镜像源,有时可能需要使用特定版本号(如 $releasever.2-stream
),具体取决于你使用的 CentOS Stream 版本。
网易镜像源
[baseos]
name=CentOS Stream $releasever - BaseOS - 163
baseurl=http://mirrors.163.com/centos/$releasever-stream/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
[appstream]
name=CentOS Stream $releasever - AppStream - 163
baseurl=http://mirrors.163.com/centos/$releasever-stream/AppStream/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
[extras]
name=CentOS Stream $releasever - Extras - 163
baseurl=http://mirrors.163.com/centos/$releasever-stream/extras/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
[powertools]
name=CentOS Stream $releasever - PowerTools - 163
baseurl=http://mirrors.163.com/centos/$releasever-stream/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
应用新的镜像源配置
完成上述配置后,请执行以下命令以清理缓存并生成新的元数据:
sudo dnf clean all
sudo dnf makecache
这将确保你能够立即使用新配置的镜像源进行软件包的安装和更新。
总结
通过替换或创建 /etc/yum.repos.d/CentOS-Stream.repo
文件中的内容为上述任意一个镜像源配置,你可以显著提高 dnf
操作的速度和稳定性。选择最接近你地理位置或网络条件最好的镜像源可以获得最佳效果。