阿里7.x
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo


yum makecache
备份源yum源
如果是国内下载的CentOS很可能国内YUM源已经设置好了。
备份/etc/yum.repos.d/下的*.repo文件 
删除全部
推荐使用#清华大学 https://mirrors.cnnic.cn/help/centos/ 

cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
cp CentOS-Base.repo CentOS-Base.repo.bak
#阿里镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#腾讯
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
#清华镜像源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo



yum clean all #清空源 可不使用此命令
yum makecache # 生成yum缓存



查看系统可用的yum源和所有的yum源
yum repolist enabled
yum repolist all