#!/bin/bash
centos6d(){
release=`cat /etc/redhat-release |grep release | awk -F" " '{print $3}' | awk -F"." '{print $1}'` ; echo "centos 版本为: $release "
case "$release" in
"6") echo " 当前匹配centos 版本为 6"
repo="/etc/yum.repos.d/centos6-epel.repo"
if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget work.eisc.cn/ruanjian/rpm/yumrepo/centos6-epel.repo
wget work.eisc.cn/ruanjian/rpm/yumrepo/centos6.repo
yum clean all # 清除原有缓存
yum makecache # 生成新的缓存
# make cache [me?k] [ka?] 制作 缓存{ka xi}
yum list # 校验yum
cd
else
echo "yum已经切换"
fi
;;
*) echo "低版本未匹配到,正在匹配红帽版本配置yum !!!"
redhat8d
;;
esac
}
centos7(){
repo="/etc/yum.repos.d/epel-7.repo"
if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget work.eisc.cn/ruanjian/rpm/yumrepo/Centos-7.repo
wget work.eisc.cn/ruanjian/rpm/yumrepo/epel-7.repo
# wget http://mirrors.aliyun.com/repo/Centos-7.repo
# wget http://mirrors.aliyun.com/repo/epel-7.repo
# 移动两个文件到 目录
#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
#sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
# sed -i 's/$releasever/7/g' /etc/yum.repos.d/*
# yum源没有对应版本包匹配;修改yum为centos7
yum clean all # 清除原有缓存
yum makecache # 生成新的缓存
# make cache [me?k] [ka?] 制作 缓存{ka xi}
yum list # 校验yum
cd
else
echo "yum已经切换"
fi
}
centos8(){
repo="/etc/yum.repos.d/Centos-8.repo"
if [ ! -e $repo ]; then
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/centos8.repo
wget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/epel.repo
yum clean all #清理缓存
yum makecache #更新源
else
echo "yum已经切换"
fi
}
redhat8d(){
release=`cat /etc/redhat-release |grep release | awk -F" " '{print $6}' | awk -F"." '{print $1}'` ; echo "redhat 版本为: $release "
case "$release" in
"8") echo " 当前匹配redhat 版本为 8"
repo="/etc/yum.repos.d/Centos-8.repo"
if [ ! -e $repo ]; then
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
yum clean all && yum makecache
else
echo "yum已经切换"
fi
;;
*) echo "红帽版本未匹配到,退出!!!"
;;
esac
}
release=`cat /etc/redhat-release |grep release | awk -F" " '{print $4}' | awk -F"." '{print $1}'` ; echo "centos 版本为: $release "
case "$release" in
"6") echo " 当前匹配centos 版本为 6"
centos6
;;
"7") echo " 当前匹配centos 版本为 7"
centos7
;;
"8") echo "当前匹配centos 版本为 8"
centos8
;;
*) echo "您的centos过于老旧,正在匹配低版本"
centos6d
;;
esac
# 清华 apt 源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# centos 6 切换yum: https://help.aliyun.com/document_detail/193569.htm
# 一键切换yum执行: wget www.eisc.cn/file/shell/centos-yum.sh ; sh centos-yum.sh
# 感谢网友提供yum解决方案:https://developer.aliyun.com/article/748336
# 阿里巴巴开源镜像站,镜像仓库: https://developer.aliyun.com/mirror/
# 阿里云linux系统镜像: https://mirrors.aliyun.com/centos-vault/
1. /etc/yum.repos.d 文件夹里面的文件全部移动到其他目录,重新部署 yum
2. 辛苦切换一下yum :https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11Pi5Ktu
#---------- alibaba3 -----------#
mkdir /yumback
mv /etc/yum.repos.d/* /yumback
wget work.eisc.cn/ruanjian/rpm/yumrepo/alibaba3/AliYun.repo -O /etc/yum.repos.d/al3.repo
wget work.eisc.cn/ruanjian/rpm/yumrepo/alibaba3/epel.repo -O /etc/yum.repos.d/epel3.repo
yum clear all ; yum list
#--------- centos8 停止维护,更换yum -------------#
停止维护公告:https://help.aliyun.com/noticelist/articleid/1060980265.html
Powered by ddoss.cn 12.0
©2015 - 2024 ddoss
渝公网安备50011302222260号 渝ICP备2024035333号 【实验平台安全承诺书】 小绿叶技术社区,优化网络中,点击查看配置信息
您的IP:192.168.122.82,2024-10-10 18:56:20,Processed in 0.02939 second(s).