【运维实用脚本】GNU/Linux一键更换系统软件源

如何解决国外系统软件

下载源访问过慢的问题?

经过考察国内镜像站的系统适配情况,测试下载速度与IPv6协议的兼容性,并全网收集大陆教育网镜像站和海外各大镜像站供选择参考,今天分享一个GNU/Linux 更换系统软件下载源脚本,加速国内下载软件的速度,操作如下:

这是一个 Bash 脚本,包含了您提到的所有命令,并且根据操作系统的不同进行了相应的处理。请根据您的需要进行修改和使用。

#!/bin/bash

# 更改 Alpine Linux 的源

update_alpine_sources() {echo "更新 Alpine Linux 源..."

 #替换为中科大源

sed-i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

#替换为阿里源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

 #替换为清华源​​​​​​​

sed-i's/dl-cdn.alpinelinux.org/mirror.tuna.tsinghua.edu.cn/g' /etc/apk/repositories

  #替换为华为源​​​​​​​

sed-i's/dl-cdn.alpinelinux.org/mirrors.huaweicloud.com/g' /etc/apk/repositories echo "Alpine Linux 源更新完成。" }

# 更改 Debian 的源​​​​​​​

update_debian_sources() {echo "更新 Debian 源..."

  #替换为阿里源​​​​​​​

sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.listsed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && apt-get update

#替换为清华源​​​​​​​

sed-i's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.listsed-i's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && apt-get update

  #替换为腾讯源​​​​​​​

sed -i 's/deb.debian.org/mirrors.cloud.tencent.com/g' /etc/apt/sources.listsed-i's/security.debian.org/mirrors.cloud.tencent.com/g' /etc/apt/sources.list && apt-get update

 #替换为华为源​​​​​​​

sed -i 's/deb.debian.org/mirrors.huaweicloud.com/g' /etc/apt/sources.listsed-i's/security.debian.org/mirrors.huaweicloud.com/g' /etc/apt/sources.list && apt-get update

#替换为中科大源​​​​​​​

sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.listsed-i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && apt-get update echo "Debian 源更新完成。"}

# 更改 Ubuntu 的源​​​​​​​

update_ubuntu_sources() {echo "更新 Ubuntu 源..."

  #替换为阿里源​​​​​​​

sed-is@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.listsed-is@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && apt-get update

  #替换为清华源​​​​​​​

sed-is@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.listsed-is@/security.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && apt-get update

#替换为腾讯源​​​​​​​

sed-is@/archive.ubuntu.com/@/mirrors.cloud.tencent.com/@g /etc/apt/sources.listsed-is@/security.ubuntu.com/@/mirrors.cloud.tencent.com/@g /etc/apt/sources.list && apt-get update

#替换为华为源​​​​​​​

sed-is@/archive.ubuntu.com/@/mirrors.huaweicloud.com/@g /etc/apt/sources.listsed-is@/security.ubuntu.com/@/mirrors.huaweicloud.com/@g /etc/apt/sources.list && apt-get update

#替换为中科大源​​​​​​​

sed-is@/archive.ubuntu.com/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.listsed-is@/security.ubuntu.com/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && apt-get updateecho "Ubuntu 源更新完成。"}

# 更改 CentOS 7 的源​​​​​​​

update_centos7_sources() {  echo "更新 CentOS 7 源..."

 # 替换阿里源​​​​​​​

echo "切换到阿里源..."mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.`date +"%Y%m%d%H%M"`curl-o/etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repocurl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repoyum clean allyum makecache

 # 替换腾讯源​​​​​​​

echo "切换到腾讯源..."mv/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.`date +"%Y%m%d%H%M"`curl-o/etc/yum.repos.d/CentOS-Base.repo https://mirrors.cloud.tencent.com/repo/centos7_base.repocurl-o/etc/yum.repos.d/epel.repo https://mirrors.cloud.tencent.com/repo/epel-7.repo  yum clean all  yum makecache  echo "CentOS 7 源更新完成。"}

# 检查并调用相应的函数​​​​​​​

if [ -f /etc/alpine-release ]; thenupdate_alpine_sourceselif [ -f /etc/debian_version ]; thenupdate_debian_sourceselif [ -f /etc/lsb-release ] && grep -q "Ubuntu" /etc/lsb-release; thenupdate_ubuntu_sourceselif [ -f /etc/centos-release ]; thenupdate_centos7_sourceselseecho "无法识别的操作系统。"exit 1fiecho "所有操作完成。"

补充

需要其它脚本可以使用开源脚本 官网:https://linuxmirrors.cn/

bash <(curl -sSL https://linuxmirrors.cn/main.sh)

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值