更改yum源

备份原镜像文件,出错后可以恢复

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

第一种方式:命令

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

第二种方式:脚本

vi yum.sh
#!/bin/bash
mv /etc/yum.repos.d/* /mnt
a=`cat /etc/redhat-release |awk '{print $3}'|awk -F . '{print $1}'`
if [ $a == 6 ];then
   wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
else
   wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
fi
yum clean all
yum makecache
chmod 777 yum.sh 
./yum.sh

备注
阿里yum源
CentOS 5

http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6

http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7

http://mirrors.aliyun.com/repo/Centos-7.repo

阿里巴巴镜像站
https://opsx.alibaba.com/mirror

posted @ 2019-06-08 19:35  冷20979  阅读(13)  评论(0编辑  收藏  举报