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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章