欢迎光临
我们一直在努力

CentOS 系统更换 yum 源为阿里源,及问题排错

第一步:备份你的原镜像文件,以免出错后可以恢复。

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

第二步:下载新的阿里源CentOS-Base.repo 到 /etc/yum.repos.d

# 对于 CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

# 对于 CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

第三步:运行 yum makecache 生成缓存

yum makecache

如果显示以下错误信息:

CentOS-8 - Base - mirrors.aliyun.com                                                                                                 76  B/s | 2.3 kB     00:30    
Errors during downloading metadata for repository 'base':
  - Status code: 404 for https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 222.218.83.244)
  - Curl error (6): Couldn't resolve host name for http://mirrors.cloud.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Could not resolve host: mirrors.cloud.aliyuncs.com]
  - Curl error (28): Timeout was reached for http://mirrors.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Connection timed out after 30001 milliseconds]
Error: Failed to download metadata for repo 'base': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were trie

则:

# 把CentOS-Base.repo文件中的以下网址
mirrors.aliyun.com/centos/
mirrors.aliyuncs.com/centos/
mirrors.cloud.aliyuncs.com/centos/
# 替换成
mirrors.aliyun.com/centos-vault/centos/

# 把epel.repo文件中的
enabled=1
# 修改成
enabled=0

或者直接把以下配置文件覆写到CentOS-Base.repo

# CentOS-Base.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 and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/extras/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/extras/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos-vault/centos/RPM-GPG-KEY-CentOS-Official

[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos-vault/centos/RPM-GPG-KEY-CentOS-Official

[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.aliyun.com/centos-vault/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/centos/RPM-GPG-KEY-CentOS-Official

第四步:查看当前yum源

yum repolist

输出:

repo id                                                           repo name
AppStream                                                         CentOS-8 - AppStream - mirrors.aliyun.com
base                                                              CentOS-8 - Base - mirrors.aliyun.com
extras                                                            CentOS-8 - Extras - mirrors.aliyun.com

Tips:可能用到的命令

# vim命令模式取代所有
:
%s/原字符字符串/新字符串/g

好了,成功了!有啥问题可以留言!

赞(0)
未经允许不得转载:拆东墙 » CentOS 系统更换 yum 源为阿里源,及问题排错

评论 抢沙发

登录

找回密码

注册