Redhat7和CentOS7系统配置阿里源失败问题及解决办法([Errno 14] HTTP Error 404 - Not Found)


一、配置阿里源


   第1步:下载阿里源的配置文件

[root@linuxprobe ~]# cd /etc/yum.repos.d/ [root@linuxprobe yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo

  第2步:将下载的配置文件重命名

[root@linuxprobe yum.repos.d]# mv Centos-7.repo Centos-Base.repo [root@linuxprobe yum.repos.d]# [root@linuxprobe yum.repos.d]# ls Centos-Base.repo  packagekit-media.repo  rhel7.repo           //其中rhel7.repo为自己配置的本地Yum软件仓库

  第3步:更新镜像源

[root@linuxprobe yum.repos.d]# yum clean all //清楚缓存 Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Cleaning repos: base extras updates Cleaning up everything [root@linuxprobe yum.repos.d]# [root@linuxprobe yum.repos.d]# yum makecache //生成缓存 Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. http://mirrors.aliyun.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found 
Trying other mirror. http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused"
Trying other mirror.
^C Current download cancelled, interrupt (ctrl-c) again within two seconds to exit.

 二、配置失败


   失败现象:在执行"yum makecache"命令的过程中,不断出现如下的错误提示:

http://mirrors.aliyun.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found 
Trying other mirror. http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused"
Trying other mirror.
---------------------------------------省略部分输出内容--------------------------------------------

   失败原因:Centos-Base.repo配置文件中的$releasever变量解析错误,导致整个URL地址错误。这种情况一般发生在Redhat系统安装Centos源(我的系统是Redhat 7)

  我为什么说是URL地址错误呢?因为我在浏览器中输入地址 "http://mirrors.aliyun.com/centos/",发现并无 7Server/目录。因此,应该是$releasever变量解析成了"7Server",进而导致了错误的发生。

  经检查发现,正确的URL地址为 http://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml,其中的"7"是指系统版本号。

三、解决办法


   这里给出我的解决办法,仅供参考:

  第1步:编辑阿里源配置文件

[root@linuxprobe yum.repos.d]# vim Centos-Base.repo

  第2步:将全文中所有的 "$releasever" 字符串替换成 "7",因为我的系统是7版本

  • 输入 ":" 进入末行模式
  • 然后输入 %s/$releasever/7/g 
  • 保存并退出

   第3步:再次更新镜像源

[root@linuxprobe yum.repos.d]# yum clean all Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Cleaning repos: base extras rhel7 updates Cleaning up everything [root@linuxprobe yum.repos.d]# yum makecache Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. base                                                                                                                                  | 3.6 kB  00:00:00 extras | 2.9 kB  00:00:00 rhel7 | 4.1 kB  00:00:00 updates | 2.9 kB  00:00:00 (1/14): base/x86_64/group_gz                                                                                                          | 165 kB  00:00:02 (2/14): extras/x86_64/filelists_db                                                                                                    | 217 kB  00:00:02 (3/14): extras/x86_64/other_db                                                                                                        | 106 kB  00:00:00 (4/14): rhel7/group_gz                                                                                                                | 134 kB  00:00:00 (5/14): base/x86_64/other_db                                                                                                          | 2.6 MB  00:00:02 (6/14): rhel7/filelists_db                                                                                                            | 3.0 MB  00:00:00 (7/14): rhel7/primary_db                                                                                                              | 3.4 MB  00:00:00 (8/14): rhel7/other_db                                                                                                                | 1.3 MB  00:00:00 (9/14): updates/x86_64/filelists_db                                                                                                   | 4.5 MB  00:00:00 (10/14): updates/x86_64/other_db                                                                                                      | 573 kB  00:00:00 (11/14): updates/x86_64/primary_db                                                                                                    | 7.6 MB  00:00:03     
base/x86_64/primary_db         FAILED                                          ========================                    ] 796 kB/s |  23 MB  00:00:17 ETA http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: [Errno -1] Metadata file does not match checksum
Trying other mirror. (12/14): base/x86_64/primary_db                                                                                                       | 6.0 MB  00:00:00     
base/x86_64/filelists_db FAILED http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/41232548001a78473ae0f2d4b92e1ec28f7a0593e0495056515887fe2a39b416-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror. (13/14): base/x86_64/filelists_db                                                                                                     | 7.3 MB  00:00:00 extras/x86_64/primary_db FAILED http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/b6838225b7b16a5eb051c048d2c0783111dc724393b62c685324b08c31d295cb-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror. (14/14): extras/x86_64/primary_db                                                                                                     | 165 kB  00:00:00 Metadata Cache Created  //缓存创建完成

四、结果检验


   我们尝试安装Apache服务程序来检测阿里源是否配置成功,如下所示:

[root@linuxprobe yum.repos.d]# yum install -y httpd Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-17.el7 will be updated ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be an update --> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64 --> Running transaction check ---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be updated ---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================= Updating: httpd x86_64 2.4.6-90.el7.centos                             base                           2.7 M Updating for dependencies: httpd-tools                           x86_64                           2.4.6-90.el7.centos                             base                            91 k Transaction Summary ============================================================================================================================================================= Upgrade 1 Package (+1 Dependent package) Total download size: 2.8 M Downloading packages: No Presto metadata available for base warning: /var/cache/yum/x86_64/7Server/base/packages/httpd-tools-2.4.6-90.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY- ETA Public key for httpd-tools-2.4.6-90.el7.centos.x86_64.rpm is not installed (1/2): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                                                                     |  91 kB  00:00:02 (2/2): httpd-2.4.6-90.el7.centos.x86_64.rpm                                                                                           | 2.7 MB  00:00:02     
------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 994 kB/s | 2.8 MB  00:00:02 Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 From : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                    1/4 Updating : httpd-2.4.6-90.el7.centos.x86_64                                                                                                          2/4 Cleanup : httpd-2.4.6-17.el7.x86_64                                                                                                                 3/4 Cleanup : httpd-tools-2.4.6-17.el7.x86_64                                                                                                           4/4 Verifying : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                    1/4 Verifying : httpd-2.4.6-90.el7.centos.x86_64                                                                                                          2/4 Verifying : httpd-tools-2.4.6-17.el7.x86_64                                                                                                           3/4 Verifying : httpd-2.4.6-17.el7.x86_64                                                                                                                 4/4 Updated: httpd.x86_64 0:2.4.6-90.el7.centos Dependency Updated: httpd-tools.x86_64 0:2.4.6-90.el7.centos Complete! //安装成功

 最后


   之前我自己的Redhat虚拟机一直使用的本地Yum源,今天想安装一个程序的时候发现没有相应的软件包,于是想到了配置一个阿里的Yum源。然而,在配置的过程中遇到了上述的问题,幸好通过查阅相关的博客找到了解决问题的办法。不过这个方法直接把路径写死了,感觉不太灵活,希望能帮助到各位!!!!

  PS:在修改配置文件后,重新执行yum makecache命令的时候还是出现了地址无法访问的报错信息,其实这个并不影响。如果不想看到报错信息的话,把下图中红色框框内的信息删掉就可以了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM