linux centos6/7/8 redhat8自动 切换yum源

简介: 自动切换yum源

#!/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

                                               # 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 -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

#sed -i 's/$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

wget -O /etc/yum.repos.d/epel8.repo work.eisc.cn/ruanjian/rpm/yumrepo/epel8.repo

#sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*

#sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

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 -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

#sed -i 's/$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

wget -O /etc/yum.repos.d/epel8.repo work.eisc.cn/ruanjian/rpm/yumrepo/epel8.repo

#sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*

#sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

yum clean all ; yum makecache  ; yum list

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

# centos 6 切换yum: https://help.aliyun.com/document_detail/193569.htm

# 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/

目录
相关文章
|
安全 Linux 数据安全/隐私保护
Red Hat Enterprise Linux 9.6 (x86_64, aarch64) - 红帽企业 Linux (RHEL)
Red Hat Enterprise Linux 9.6 (x86_64, aarch64) - 红帽企业 Linux (RHEL)
1796 36
Red Hat Enterprise Linux 9.6 (x86_64, aarch64) - 红帽企业 Linux (RHEL)
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
3111 16
|
Linux
Centos6配置阿里云yum源报错
在CentOS 6配置阿里云Yum源时,可能出现EPEL仓库访问报错(404 Not Found)。解决方法:编辑`/etc/yum.repos.d/epel.repo`文件,将`enabled`和`gpgcheck`参数设为0 ``` 此设置可解决仓库无法访问的问题。
2718 29
|
Linux 数据库
Red Hat Enterprise Linux(RHEL)
Red Hat(红帽)是一家美国的软件公司,专注于开发开源软件产品。公司成立于1993年,总部位于美国北卡罗来纳州的罗利市。目前,Red Hat已成为全球最大的开源解决方案提供商和商业Linux主要供应商。 Red Hat由Bob Young和Marc Ewing共同创立。Marc Ewing最初创建了自己的Linux发行版,并将其命名为红帽Linux。1995年,Bob Young收购了Marc Ewing的企业,两者合并成为红帽软件公司。此后,红帽Linux逐渐发展成为一款备受欢迎的Linux发行版。 特点
831 10
Red Hat Enterprise Linux(RHEL)
|
人工智能 安全 Linux
Red Hat Enterprise Linux 10 正式版发布 - 红帽企业 Linux (RHEL)
Red Hat Enterprise Linux 10 正式版发布 - 红帽企业 Linux (RHEL)
1917 0
Red Hat Enterprise Linux 10 正式版发布 - 红帽企业 Linux (RHEL)
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
2036 25
|
缓存 Linux
CentOS-6的iso下载地址镜像yum源
通过上述步骤,您可以成功下载CentOS 6的ISO镜像文件,并配置适用于CentOS 6的YUM源。尽管CentOS 6已经停止更新,但使用这些镜像和YUM源配置,可以继续在需要的环境中使用和维护CentOS 6系统。
9496 20
|
人工智能 Java 关系型数据库
Red Hat Enterprise Linux 9.5 发布下载,新增功能亮点概述
Red Hat Enterprise Linux 9.5 发布下载,新增功能亮点概述
1408 4
Red Hat Enterprise Linux 9.5 发布下载,新增功能亮点概述
|
Linux 虚拟化 开发者
一键将CentOs的yum源更换为国内阿里yum源
一键将CentOs的yum源更换为国内阿里yum源
24568 31
CentOs9 yum源出现404问题
CentOs9-stream yum源出现404问题