Linux下载时出现的错误(配置阿里云镜像解决)
linux下载时出现的下面错误
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
从错误信息来看,CentOS 系统尝试访问 mirrorlist.centos.org 来获取软件包仓库的镜像列表时失败了。
这个错误通常是因为CentOS 7 已经到达了它的生命周期结束(EOL),这意味着官方不再维护和更新该版本的软件仓库。因此,mirrorlist.centos.org 可能已经不再提供适用于 CentOS 7 的镜像列表,或者相关的服务器已经被移除或重定向到其他地方。
解决方法:配置阿里云镜像
配置 Linux 系统使用阿里云镜像可以加快软件包的下载速度,并提高系统的更新效率。
对于 CentOS备份原有的仓库文件:
在进行任何更改之前,建议先备份现有的仓库配置文件,防止出错快速回复
sudo cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
替换为阿里云镜像源:
你可以直接编辑 /etc/yum.repos.d/CentOS-Base.repo 文件,或者下载阿里云提供的配置文件。
# 修改CentOS-Base.repo 文件
vi /etc/yum.repos.d/CentOS-Base.repo
手动编辑:将原有内容替换为以下内容(以 CentOS 7 为例):
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
生成缓存:
更新完仓库配置后,需要清除旧的缓存并生成新的缓存:
sudo yum clean all
sudo yum makecache