1.备份
先cd到yum.repos.d目录下,ls查看下目录下都有什么
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
再创建repo_bak目录吧这些文件都移过去作为备份
[root@localhost yum.repos.d]# mkdir repo_bak
root@localhost yum.repos.d]# mv *.repo repo_bak/
2.下载阿里的CentOS-Base.repo 到/etc/yum.repos.d/
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
ls可以常看到在刚刚创建的备份文件旁边出现了新的文件CentOS-Base.repo
3、运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
4.安装EPEL源
[root@localhost yum.repos.d]# yum list | grep epel-release
epel-release.noarch 7-11 extras
[root@localhost yum.repos.d]# yum install -y epel-release
再次ls查看此时又多了epel.repo 和epel-testing.repo两个文件
[root@localhost yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo repo_bak
5.再次运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
root@localhost yum.repos.d]# yum repolist enabled #查看启用的仓库
[root@localhost yum.repos.d]# yum repolist all #查看所有的仓库