动态 版块 发帖 消息 我的
Loading...
小绿叶技术博客
小绿叶技术博客
小绿叶技术Lv149   
linux centos6/7/8自动 切换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

# 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

更换yum:https://help.aliyun.com/document_detail/405635.html

迁移服务器系统:https://help.aliyun.com/document_detail/370865.htm?spm=a2c4g.11186623.0.0.58863201lhpfjW#task-2156316

 0  已被阅读了1665次  楼主 2020-04-01 16:34:36
回复列表
admin
10F
小绿叶技术Lv149   
ubuntu20 清华apt 源:



# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse


# 预发布软件源,不建议启用

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse


 0   2022-04-07 12:43:29  回复
admin
9F
小绿叶技术Lv149   
华为云  apt  源:https://mirrors.huaweicloud.com/home?utm_source=3.baidu.com&utm_medium=organic&utm_adplace=kapian
 0   2022-04-07 12:32:59  回复
admin
8F
小绿叶技术Lv149   

#该yum 仅仅试用与专有网络centos8 系统

cd /etc/yum.repos.d

mkdir /yumback

mv /etc/yum.repos.d/* /yumback

wget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/zy/CentOS-Base.repo

wget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/zy/epel8.repo

yum list

 0   2022-02-03 00:07:19  回复
admin
7F
小绿叶技术Lv149   

这边测试无法登录服务器,您是否可以登录服务器呢,如果可以,这边协助您更换yum吧

ls /etc/yum.repos.d

# 查看yum 文件


mkdir /yumbak

# 创建yum备份文件


mv /etc/yum.repos.d/* mkdir /yumbak

# 将yum文件移动到 备份目录


cd /etc/yum.repos.d/


根据:centos6 切换yum 参考:https://help.aliyun.com/document_detail/193569.htm

vi c.repo

写入经典网络


vi e.repo

写入epel


yum clean all ; yum makecache ; yum list

# 生成新yum

 0   2021-11-24 16:13:25  回复
admin
5F
小绿叶技术Lv149   
阿里云 centos8.2  : https://mirrors.aliyun.com/centos-vault/8.2.2004/isos/x86_64/
 0   2021-10-14 21:56:20  回复

回复:linux centos6/7/8自动 切换yum源

guest
登录之后更精彩~
Powered by HadSky 7.7.16
© 2015-2022 PuYueTian
您的IP:8.219.134.200,2022-08-10 07:19:13,Processed in 0.0182 second(s).
Powered by HadSky
小绿叶技术博客