如何解决国外系统软件
下载源访问过慢的问题?
经过考察国内镜像站的系统适配情况,测试下载速度与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.list
sed -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.list
sed-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.list
sed-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.list
sed-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.list
sed-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.list
sed-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.list
sed-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.list
sed-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.list
sed-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.list
sed-is@/security.ubuntu.com/@/mirrors.ustc.edu.cn
/@g /etc/apt/sources.list && apt-get update
echo "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.repo
curl -o /etc/yum.repos.d/epel.repo http://
mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum 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.repo
curl-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 ]; then
update_alpine_sources
elif [ -f /etc/debian_version ]; then
update_debian_sources
elif [ -f /etc/lsb-release ] && grep -q "Ubuntu"
/etc/lsb-release; then
update_ubuntu_sources
elif [ -f /etc/centos-release ]; then
update_centos7_sources
else
echo "无法识别的操作系统。"
exit 1
fi
echo "所有操作完成。"
补充
需要其它脚本可以使用开源脚本 官网:https://linuxmirrors.cn/
bash <(curl -sSL https://linuxmirrors.cn/main.sh)