站点图标 IDC铺

解决提示“Cannot retrieve metalink for repository: epel/x86_64” 的方法

今天在centos7服务器上用yum的时候发现,yum命令不能用了,不管用yum什么命令都会出现如下提示:

1、错误提示一:

One of the configured repositories failed (Unknown),and yum doesn’t have enough cached data to continue.

中文翻译

其中一个已配置的存储库失败(未知),并且yum没有足够的缓存数据可以继续。

 

2、错误提示二:

Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again

中文翻译

无法检索存储库的metalink:epel / x86_64。 请验证其路径,然后重试

 

3、完整的错误提示如下:

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. Disable the repository, 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>

     4. 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 retrieve metalink for repository: epel/x86_64. Please verify its path and try again

按照网上很多资料都没有解决我的问题,因为:

1、我的服务器 ping 正常的,无论是ping镜像还是ping其它网站都可以ping通。

2、/etc/resolv.conf 里面的 nameserver 114.114.114.114 也是有的,dns也没问题。

解决方法

想要解决问题,必须先要找原因,很多人碰上如上图这种错误的时候,都会首先认为是“错误提示一”这个问题,如果这样想,其实就大错特错了。

出现此问题,最根本的原因是“/etc/yum.repos.d/epel.repo”里面的镜像源路径不对。

既然找到了原因,解决起来就容易多了,具体步骤如下:

1、打开 /etc/yum.repos.d/epel.repo;

/etc/yum.repos.d/epel.repo

2、注释掉mirrorlist,取消注释baseurl;

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch

修改为

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch

3、再次使用yum命令即正常!

yum clean all

yum makecache

yum update

yum install -y lsof

退出移动版