HCRM博客

CentOS系统更换镜像时,具体操作步骤及注意事项有哪些?

在Linux系统中,CentOS是一个广泛使用的操作系统,为了优化性能或解决兼容性问题,用户可能会选择更换CentOS的镜像源,以下是关于如何在CentOS中更换镜像源的详细指南。

CentOS系统更换镜像时,具体操作步骤及注意事项有哪些?-图1

了解镜像源

镜像源是指存储软件包的地方,它可以是官方源,也可以是第三方提供的源,更换镜像源的主要目的是提高软件包下载速度,或者获取到特定版本的软件包。

更换CentOS 7镜像源

查看当前镜像源

在终端中输入以下命令,查看当前使用的镜像源:

cat /etc/yum.repos.d/CentOS-Base.repo

下载并替换镜像源

以下是一个常用的CentOS 7镜像源列表,您可以根据需要选择合适的源进行替换。

国内常用镜像源:

镜像源名称镜像源地址
网易163http://mirrors.163.com/centos/7/
阿里云http://mirrors.aliyun.com/centos/7/
禹盟http://mirrors.yun-idc.com/centos/7/
网易163(64位)http://mirrors.163.com/centos/7/os/
阿里云(64位)http://mirrors.aliyun.com/centos/7/os/
禹盟(64位)http://mirrors.yun-idc.com/centos/7/os/

替换步骤:

使用文本编辑器打开镜像源配置文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

删除原有的镜像源配置,并粘贴以下内容(以网易163为例):

[base]
name=CentOS-7 - Base
mirrorlist=http://mirrors.163.com/mirrors/centos/mirrorlist?release=7&arch=x86_64&repo=base&infra=client
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[epel]
name=CentOS-7 - EPEL (Extra Packages for Enterprise Linux)
mirrorlist=http://mirrors.163.com/mirrors/centos/mirrorlist?release=7&arch=x86_64&repo=epel&infra=client
baseurl=http://mirrors.163.com/centos/7/epel/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

保存并关闭文件。

更新本地缓存

在终端中执行以下命令,更新本地缓存:

CentOS系统更换镜像时,具体操作步骤及注意事项有哪些?-图2

sudo yum makecache

更换CentOS 8镜像源

CentOS 8的镜像源更换步骤与CentOS 7类似,以下是具体步骤:

查看当前镜像源

cat /etc/yum.repos.d/CentOS-Base.repo

下载并替换镜像源

国内常用镜像源:

镜像源名称镜像源地址
网易163http://mirrors.163.com/centos/8/
阿里云http://mirrors.aliyun.com/centos/8/
禹盟http://mirrors.yun-idc.com/centos/8/
网易163(64位)http://mirrors.163.com/centos/8/os/x86_64/
阿里云(64位)http://mirrors.aliyun.com/centos/8/os/x86_64/
禹盟(64位)http://mirrors.yun-idc.com/centos/8/os/x86_64/

替换步骤:

使用文本编辑器打开镜像源配置文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

删除原有的镜像源配置,并粘贴以下内容(以网易163为例):

[base]
name=CentOS Linux $releasever - Base
mirrorlist=http://mirrors.163.com/mirrors/centos/mirrorlist?release=8&arch=x86_64&repo=base&infra=client
baseurl=http://mirrors.163.com/centos/8/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[epel]
name=CentOS Linux $releasever - EPEL (Extra Packages for Enterprise Linux)
mirrorlist=http://mirrors.163.com/mirrors/centos/mirrorlist?release=8&arch=x86_64&repo=epel&infra=client
baseurl=http://mirrors.163.com/centos/8/epel/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

保存并关闭文件。

更新本地缓存

sudo yum makecache

FAQs

Q1:更换镜像源后,如何验证是否成功?

A1:您可以通过以下命令查看当前使用的镜像源:

yum repolist enabled

如果看到新的镜像源地址,则说明更换成功。

CentOS系统更换镜像时,具体操作步骤及注意事项有哪些?-图3

Q2:更换镜像源后,如何恢复到默认的官方源?

A2:您可以通过以下步骤恢复到默认的官方源:

使用文本编辑器打开镜像源配置文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

删除自定义的镜像源配置,并粘贴以下内容:

[base]
name=CentOS-7 - Base
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=base&infra=client
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[epel]
name=CentOS-7 - EPEL (Extra Packages for Enterprise Linux)
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=epel&infra=client
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  1. 保存并关闭文件。

  2. 更新本地缓存:

sudo yum makecache

本站部分图片及内容来源网络,版权归原作者所有,转载目的为传递知识,不代表本站立场。若侵权或违规联系Email:zjx77377423@163.com 核实后第一时间删除。 转载请注明出处:https://blog.huochengrm.cn/pc/64407.html

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
请登录后评论...
游客游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~