问题

在 CentOS6.5 上执行 yum install gcc 报错:YumRepo Error: All mirror URLs are not using ftp, http[s] or file。出现这个的原因是因为目前官方已经停止对CentOS6的支持。并且下架了包括官方所有的CentOS6源,目前阿里、163、清华等CentOS6源已无法使用。

解决

1、备份,便于进行恢复

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2、下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

我这里是CenOS6,其他版本可以在 https://mirrors.aliyun.com/repo/ 中找到对应的文件

# centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

如果出现错误:

[root@Levi ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
--2022-05-15 20:44:42--  https://mirrors.aliyun.com/repo/Centos-6.repo
正在解析主机 mirrors.aliyun.com... 116.162.173.85, 116.153.65.218, 116.162.173.86, ...
正在连接 mirrors.aliyun.com|116.162.173.85|:443... 已连接。
错误: 证书通用名 “*.alicdn.com” 与所要求的主机名 “mirrors.aliyun.com” 不符。
要以不安全的方式连接至 mirrors.aliyun.com,使用‘--no-check-certificate’。

使用命令:

wget --no-check-certificate -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

3、运行 yum makecache 生成缓存

[root@Levi ~]# yum makecache
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
...

4、替换源文件配置

  1. 非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置:

    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    
  2. 替换http成https

    sed -i  's/http/https/g' /etc/yum.repos.d/CentOS-Base.repo
    
  3. 替换版本,$releasever 替换6.5,6.5是我用的版本

    sed -i  's/$releasever/6.5/g' /etc/yum.repos.d/CentOS-Base.repo
    
  4. 替换centos为centos-vault

    sed -i  's/centos/centos-vault/g' /etc/yum.repos.d/CentOS-Base.repo
    

5、执行 yum clean all && yum makecache

[root@Levi ~]# yum clean all && yum makecache
Loaded plugins: fastestmirror, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, security
Determining fastest mirrors
base                                                     | 3.7 kB     00:00     
base/group_gz                                            | 226 kB     00:00     
base/filelists_db                                        | 6.4 MB     00:01     
base/primary_db                                          | 4.7 MB     00:00     
base/other_db                                            | 2.8 MB     00:00     
extras                                                   | 3.4 kB     00:00     
extras/filelists_db                                      |  38 kB     00:00     
extras/prestodelta                                       | 1.3 kB     00:00     
extras/primary_db                                        |  37 kB     00:00     
extras/other_db                                          |  51 kB     00:00     
updates                                                  | 3.4 kB     00:00     
updates/filelists_db                                     | 3.5 MB     00:00     
updates/prestodelta                                      | 390 kB     00:00     
updates/primary_db                                       | 5.4 MB     00:00     
updates/other_db                                         |  74 MB     00:13   
Metadata Cache Created

参考


YOLO