栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

更换阿里云Yum源脚本

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更换阿里云Yum源脚本

[root@haimati shell]# cat Yum_Aliyun.sh 
#!/bin/bash
# 替换默认Yum源为 国内阿里云Yum源
# 适用于Linux Centos 6-8 版本!

. /etc/init.d/functions

REDHAT=$(cat /etc/redhat-release  | awk  '{print $4}'| awk -F . '{print $1}')

if [ $REDHAT -eq 7 ];then
	
	if !  [ -d /etc/yum.repos.d/Yum.bak ];then
		mkdir /etc/yum.repos.d/Yum.bak/
	fi

	mv /etc/yum.repos.d/CentOS-base.repo /etc/yum.repos.d/Yum.bak
	mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/Yum.bak

	(wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo) &>/dev/null

	if [ $? -eq 0 ];then
		action "Yum:"
	else
		action "Yum" false 
	fi
elif [ $REDHAT -eq 6 ];then
	
	if !  [ -d /etc/yum.repos.d/Yum.bak ];then
		mkdir /etc/yum.repos.d/Yum.bak/
	fi

	(mv /etc/yum.repos.d/CentOS-base.repo /etc/yum.repos.d/Yum.bak
	mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/Yum.bak) &>/dev/null

	(wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
	wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-6.repo) &>/dev/null


	if [ $? -eq 0 ];then
		action "Yum:"
	else
		action "Yum" false 
	fi


elif [ $REDHAT -eq 8 ];then
	
	if !  [ -d /etc/yum.repos.d/Yum.bak ];then
		mkdir /etc/yum.repos.d/Yum.bak/
	fi

	(mv /etc/yum.repos.d/CentOS-base.repo /etc/yum.repos.d/Yum.bak
	mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/Yum.bak) &>/dev/null

	(wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
	yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
	sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
	sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*) &>/dev/null


	if [ $? -eq 0 ];then
		action "Yum:"
	else
		action "Yum" false 
	fi


fi 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/730672.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号