Linux-yum镜像源问题

Later

yum的工作原理是从我们所配置的远程仓库下载rpm包,然后进行安装,远程仓库的配置文件位于/etc/yum.repos.d/目录中。

远程仓库可手动配置,也可在线配置,下面在线配置

1
[root@localhost ~]# yum -y install epel-release 

但是直接用这个命令的时候可能会碰到我这个问题:

1
2
3
4
5
6
7
8
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
12: Timeout on http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock: (28, 'Resolving timed out after 30565 milliseconds')


One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only

出现这种错误通常是因为你的服务器无法连接到 CentOS 的镜像服务器,可能是网络问题或 DNS 配置问题。我是通过手动配置镜像源来解决这个问题的,过程如下:

手动设置镜像源

1.编辑 CentOS-Base.repo 文件:

1
sudo vi /etc/yum.repos.d/CentOS-Base.repo

2.直接删掉里面的全部的东西(按esc,之后一直按D键就可以了),换成使用阿里云镜像源(按i可以输入):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3.保存并退出文件

按下esc键之后输入:号在输入wq,按下回车

4.清理缓存并重试安装 epel-release

1
2
3
sudo yum clean all
sudo yum makecache
sudo yum -y install epel-release

通过使用国内的镜像源,应该能解决由于网络连接问题导致的超时错误。如果依然出现问题,可以更换你的 /etc/resolv.conf 文件使用公共 DNS 服务器:

1
sudo vi /etc/resolv.conf

添加以下内容:

1
2
nameserver 223.5.5.5  # 阿里云公共DNS
nameserver 223.6.6.6 # 阿里云公共DNS

然后再次清理缓存并重试安装。

  • 标题: Linux-yum镜像源问题
  • 作者: Later
  • 创建于 : 2024-07-22 17:24:35
  • 更新于 : 2024-08-01 19:16:31
  • 链接: http://www.later0716.top/2024/07/22/Linux-yum镜像源问题/
  • 版权声明: 版权所有 © Later,禁止转载。