1 | vi /etc/yum.repos.d/CentOS-Base.repo |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | [base] name=CentOS-8.5.2111 - Base - mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/ http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/ gpgcheck=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that may be useful [extras] name=CentOS-8.5.2111 - Extras - mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/ http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/ gpgcheck=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official #additional packages that extend functionality of existing packages [centosplus] name=CentOS-8.5.2111 - Plus - mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/centosplus/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/ http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/ gpgcheck=0 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [PowerTools] name=CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/ gpgcheck=0 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official [AppStream] name=CentOS-8.5.2111 - AppStream - mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/ http://mirrors.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/ http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/ gpgcheck=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official |
更新于2026年05月18号
1. 新建备份目录
1 | mkdir -p /etc/yum.repos.d/backup |
2. 旧的源移到备份目录
1 | mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2>/dev/null |
3. 下换阿里云源
1 | curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo |
1 | yum clean all && yum makecache |
5.最后更新
1 | yum update -y |
================================================================
CentOS 8中 更新或下载时报错:为仓库 ‘appstream‘ 下载元数据失败 : Cannot prepare internal mirrorlist
1 | https://blog.csdn.net/lxcw_sir/article/details/140185068 |
报错信息如下:
1 2 3 4 5 | [root@localhost ~]# yum update -y CentOS-8 - AppStream 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository 'AppStream': - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org] |

原因 : CentOS Linux 8已于 2021年12月31日停止更新和维护,由于CentOS 团队从官方镜像中移除CentOS 8的所有包,所以在使用yum源安装或更新会报上述失败错误。
解决办法:
1. 进入仓库源文件夹下
1 | cd /etc/yum.repos.d/ |
2. 修改镜像配置内容
1 2 | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* |
3. 清空原有缓存,并重新生成
1 | yum clean all && yum makecache |

4. 更新软件包
1 | yum update -y |
