背景

出现如下情况,说明本地 yum 源出现问题

[root@www download]# yum install -y gcc
Loaded plugins: fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base

aliyun centos yum 源

阿里云 http://mirrors.aliyun.com/centos/6/readme 归档了源地址,我将其放在了我自己的服务器上

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://lukachen.com/resource/Centos-6-Vault-Aliyun.repo
yum clean all
yum makecache
如 yum makecache 时出现 Couldn't resolve host 'mirrors.aliyun.com'
关闭防火墙
/etc/init.d/iptables stop
vi /etc/resolv.conf

输入:
nameserver 8.8.8.8
nameserver 114.114.114.114

service network restart

安装 epel 源

yum install epel-release
如 yum makecache 时出现
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/metalink                                                                                                         | 3.8 kB     00:00     
Could not retrieve mirrorlist https://mirror.webtatic.com/yum/el6/x86_64/mirrorlist error was
14: problem making ssl connection
Error: Cannot find a valid baseurl for repo: webtatic

按 rpm 操作安装 epel 源

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

查看 yum 源列表

yum repolist -v

输出如下:
Loading "fastestmirror" plugin
Config time: 0.007
Yum Version: 3.2.29
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.yun-idc.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Setting up Package Sacks
pkgsack time: 0.048
Repo-id      : base
Repo-name    : CentOS-6 - Base - mirrors.aliyun.com
Repo-revision: 1530286202
Repo-updated : Fri Jun 29 23:37:23 2018
Repo-pkgs    : 6,713
Repo-size    : 5.5 G
Repo-baseurl : http://mirrors.aliyun.com/centos/6/os/x86_64/, http://mirrors.aliyuncs.com/centos/6/os/x86_64/, http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/
Repo-expire  : 21,600 second(s) (last: Fri Sep 27 11:19:26 2019)

Repo-id      : epel
Repo-name    : Extra Packages for Enterprise Linux 6 - x86_64
Repo-revision: 1569466679
Repo-updated : Thu Sep 26 11:00:54 2019
Repo-pkgs    : 12,570
Repo-size    : 11 G
Repo-metalink: https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64
  Updated    : Fri Sep 27 08:21:38 2019
Repo-baseurl : http://mirrors.yun-idc.com/epel/6/x86_64/ (8 more)
Repo-expire  : 21,600 second(s) (last: Fri Sep 27 11:26:10 2019)

Repo-id      : extras
Repo-name    : CentOS-6 - Extras - mirrors.aliyun.com
Repo-revision: 1554122385
Repo-updated : Mon Apr  1 20:39:45 2019
Repo-pkgs    : 46
Repo-size    : 13 M
Repo-baseurl : http://mirrors.aliyun.com/centos/6/extras/x86_64/, http://mirrors.aliyuncs.com/centos/6/extras/x86_64/, http://mirrors.cloud.aliyuncs.com/centos/6/extras/x86_64/
Repo-expire  : 21,600 second(s) (last: Fri Sep 27 11:19:33 2019)

Repo-id      : updates
Repo-name    : CentOS-6 - Updates - mirrors.aliyun.com
Repo-revision: 1568749718
Repo-updated : Wed Sep 18 03:54:00 2019
Repo-pkgs    : 609
Repo-size    : 8.2 G
Repo-baseurl : http://mirrors.aliyun.com/centos/6/updates/x86_64/, http://mirrors.aliyuncs.com/centos/6/updates/x86_64/, http://mirrors.cloud.aliyuncs.com/centos/6/updates/x86_64/
Repo-expire  : 21,600 second(s) (last: Fri Sep 27 11:19:33 2019)

repolist: 19,938