CentOS 建立源指南

CentOS 作为一款免费、开源的 Linux 发行版,因其稳定性和兼容性而受到广大用户的喜爱,在安装和配置 CentOS 时,建立合适的源是至关重要的,本文将详细介绍如何在 CentOS 上建立源,包括国内常用源的选择、配置方法以及注意事项。
选择合适的源
国内常用源
(1)阿里云镜像
阿里云镜像是中国大陆地区较为常用且速度较快的源之一,它提供了 CentOS 6、7、8 等版本的镜像。
(2)清华大学开源软件镜像
清华大学开源软件镜像也是国内较为知名的源之一,提供了 CentOS 6、7、8 等版本的镜像。
(3)华为云镜像
华为云镜像提供了 CentOS 6、7、8 等版本的镜像,速度较快。
国外常用源
(1)CentOS 官方源
CentOS 官方源提供了最稳定、最可靠的镜像,但速度可能较慢。
(2)Mirrorlist.org

Mirrorlist.org 提供了全球范围内的 CentOS 镜像列表,用户可以根据自己的地理位置选择合适的源。
配置源
使用 yum 源
(1)打开终端。
(2)编辑 /etc/yum.repos.d/CentOS-Base.repo 文件,可以使用 vi、nano 或其他文本编辑器。
(3)将以下内容替换原文件内容:
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Base&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Updates&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo= Extras&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Plus&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centos-testing]
name=CentOS-$releasever - Testing
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Testing&infra=$infra
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 (4)保存并关闭文件。
(5)运行 yum clean all 清除缓存。
(6)运行 yum makecache 生成缓存。
使用 dnf 源
(1)打开终端。
(2)编辑 /etc/dnf/repos.d/CentOS-Base.repo 文件,可以使用 vi、nano 或其他文本编辑器。
(3)将以下内容替换原文件内容:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Base&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Updates&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo= Extras&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Plus&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centos-testing]
name=CentOS-$releasever - Testing
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=Testing&infra=$infra
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 (4)保存并关闭文件。
(5)运行 dnf clean all 清除缓存。
(6)运行 dnf makecache 生成缓存。
注意事项
在选择源时,请确保所选源的速度和稳定性。
在配置源时,请确保正确替换源地址。
在生成缓存后,请确保缓存文件未被修改。
FAQs
问题:如何查看当前已配置的源?
解答:在终端中运行
yum repolist enabled或dnf repolist enabled命令,即可查看当前已配置的源。问题:如何删除已配置的源?
解答:编辑
/etc/yum.repos.d/或/etc/dnf/repos.d/目录下的相应文件,将[source_name]部分删除,然后保存并关闭文件。
【版权声明】:本站所有内容均来自网络,若无意侵犯到您的权利,请及时与我们联系将尽快删除相关内容!
发表回复