系统:CentOS 7.9

应用场景:安装数据库时,此前一直用的本地系统镜像处理安装包,直到有次在客户那里实施DG的搭建,需要配置其它的yum源.当时是遇到一些问题的,所以就有了这次配置ali源的实验测试,加深对此部分知识点的理解.

问题描述:配置yum源时,在/etc/yum.repos.d/目录下配置好.repo文件后,执行yum repolist all报警[Errno 14] HTTPS Error 404 - Not Found,如下所示:

[root@hisdg01 yum.repos.d]# ll
total 4
drwxr-xr-x. 2 root root 220 Jul 29 10:41 bak
-rw-r--r--. 1 root root 194 Jul 29 13:41 centos.repo
[root@hisdg01 yum.repos.d]# cat centos.repo
[centos7]
name=centos7
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7
[root@hisdg01 yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
repo id repo name status
centos7 centos7 enabled: 0
repolist: 0

解决方案:

1、删除原.repo文件

[root@hisdg01 yum.repos.d]# rm centos.repo
rm: remove regular file ‘centos.repo’? yes
[root@hisdg01 yum.repos.d]# ll
total 0
drwxr-xr-x. 2 root root 220 Jul 29 10:41 bak

2、卸载原yum包

说明:其实这里该包已经是最新的rpm包,不过笔者想卸载后重新安装

[root@hisdg01 ~]# rpm -qa yum
yum-3.4.3-168.el7.centos.noarch
[root@hisdg01 ~]# rpm -e --nodeps yum-3.4.3-168.el7.centos.noarch

3、下载最新rpm包

[root@hisdg01 ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
[root@hisdg01 ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@hisdg01 ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

4、安装yum包

[root@hisdg01 ~]# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@hisdg01 ~]# rpm -ivh yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
[root@hisdg01 ~]# rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm
[root@hisdg01 ~]# rpm -qa yum
yum-3.4.3-168.el7.centos.noarch

5、导入证书

[root@hisdg01 ~]# rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

6、添加阿里源

[root@hisdg01 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2022-07-29 14:16:30-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.84.36.248, 119.84.36.242, 119.84.36.239, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.84.36.248|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[======================================================================================================>] 2,523 --.-K/s in 0.001s

2022-07-29 14:16:30 (3.23 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

7、清除缓存并生成新缓存

[root@hisdg01 ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@hisdg01 ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): extras/7/x86_64/filelists_db | 277 kB 00:00:00
(3/10): extras/7/x86_64/other_db | 148 kB 00:00:00
base/7/x86_64/filelists_db FAILED ] 1.2 MB/s | 4.4 MB 00:00:33 ETA
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection timed out"
Trying other mirror.
(4/10): base/7/x86_64/other_db | 2.6 MB 00:00:03
extras/7/x86_64/primary_db FAILED ] 1.2 MB/s | 5.1 MB 00:00:31 ETA
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/68cf05df72aa885646387a4bd332a8ad72d4c97ea16d988a83418c04e2382060-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection timed out"
Trying other mirror.
base/7/x86_64/primary_db FAILED = ] 1.5 MB/s | 16 MB 00:00:18 ETA
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(5/10): extras/7/x86_64/primary_db | 247 kB 00:00:00
(6/10): updates/7/x86_64/filelists_db | 9.1 MB 00:00:11
(7/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:08
updates/7/x86_64/primary_db FAILED =======- ] 1.7 MB/s | 22 MB 00:00:12 ETA
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/59e299f8058df845fde7a3d6cf0deb765762e02688692ee0682a24377bb047f9-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
updates/7/x86_64/other_db FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/789cde875fe6737c803fa587bc13b481c0b31829bfee8fad29d3f4b35c8c6244-other.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(8/10): updates/7/x86_64/other_db | 1.1 MB 00:00:01
(9/10): base/7/x86_64/primary_db | 6.1 MB 00:00:07
(10/10): updates/7/x86_64/primary_db | 16 MB 00:00:18
Metadata Cache Created

此时可以看到在/etc/yum.repos.d/目录下自动生成CentOS-Base.repo文件

[root@hisdg01 yum.repos.d]# ll
total 4
drwxr-xr-x. 2 root root 220 Jul 29 10:41 bak
-rw-r--r--. 1 root root 2523 Dec 26 2020 CentOS-Base.repo
[root@hisdg01 yum.repos.d]# pwd
/etc/yum.repos.d
[root@hisdg01 yum.repos.d]# cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

参考网址:https://blog.csdn.net/weixin_44755863/article/details/120043333?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-120043333-blog-87281698.pc_relevant_multi_platform_whitelistv1_exp2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-120043333-blog-87281698.pc_relevant_multi_platform_whitelistv1_exp2&utm_relevant_index=2