centos更换阿里云镜像源

#!/bin/bash
#date:20200410
#author:zyq

. /etc/init.d/functions
export export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

yumAddress=/etc/yum.repos.d/CentOS-Base.repo

#确保DNS可用
cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 8.8.8.8
EOF

#备份原yum源
mv $yumAddress ${yumAddress}.bak
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
cp /etc/yum.repos.d/{,.bak}

系统版本
release=`cat /etc/redhat-release |awk -F " " '{print $3}'|cut -d "." -f 1`


#更换为aliyun的yum源
function aliyun(){
	if [ $release -eq "6" ];then
	wget -O $yumAddress http://mirrors.aliyun.com/repo/Centos-6.repo
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
	elif [ $release -eq "7" ];then
	wget -O $yumAddress http://mirrors.aliyun.com/repo/Centos-7.repo
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
	fi
	
	sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo \
	yum makecache
	yum repolist all
}
aliyun

阿里云yum源地址:https://developer.aliyun.com/mirror/

发布了4 篇原创文章 · 获赞 3 · 访问量 121

猜你喜欢

转载自blog.csdn.net/weixin_44086408/article/details/105459345
今日推荐