问题大致描述:
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; Unknown error"
问题详细描述:
最近在学习过程中,创建虚拟机centos7进行练习
在使用的过程中使用YUM安装时出现了问题
当我执行一下命令时
yum install <package-name>
出现了问题,系统描述如下:
[root@localhost ~]# yum install openssl-devel
Loaded plugins: fastestmirror
Determining fastest mirrors
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; Unknown error"
One of the configured repositories failed (Unknown),
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
导致的。这通常是由于网络连接问题或 DNS 解析问题引起的,但是我的虚拟机可以正常访问 Internet。百度,8.8.8.8都能ping通,所以我就进行更换镜像源。
解决步骤
通过更换yum仓库源进行解决,我将其更换为阿里云镜像,请根据以下步骤操作
1.从阿里云下载 CentOS 7 的 repo 文件
使用curl下载
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
如果你安装了wget,也可以使用一下命令进行下载
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2.更新镜像列表缓存,依次执行以下命令:
yum clean all
yum makecache
yum -y update
这一步需要花点时间,需要下载各种资源和更新
3.重试安装命令
yum install <package-name>
此时就能正常进行下载了