centos7-epel加速

# 对于 CentOS 7
sed -e 's|^mirrorlist= |#mirrorlist= |g' \ -e
's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsingh ua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
 
# 对于 CentOS 8
sed -e 's|^mirrorlist= |#mirrorlist= |g' \ -e
's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.t singhua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
 
 
#  CentOS Stream 9
# 将这段代码保存为一个文件,例如 update_mirror.pl #!/usr/bin/perl
 
use strict;
use warnings; use autodie;
 
my $mirrors = 'https://mirrors.tuna.tsinghua.edu.cn/centos-stream';
 
if (@ARGV < 1) {
die "Usage: $0 <filename1> <filename2> ...\n"; }
 
while (my $filename = shift @ARGV) {
my $backup_filename = $filename . '.bak'; rename $filename, $backup_filename;
 
open my $input, "<", $backup_filename; open my $output, ">", $filename;
 
while (<$input>) {
s/^metalink/# metalink/;
 
if (m/^name/) {
my (undef, $repo, $arch) = split /-/; $repo =~ s/^\s+|\s+$//g;
($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g;
 
if ($repo =~ /^Extras/) {
$_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n";
} else {
$_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") .
"\n";
} }

print $output $_; }
}
 
 
perl ./update_mirror.pl /etc/yum.repos.d/centos*.repo
 
# 如果没有perl # 使用 dnf
dnf clean all && dnf makecache
 
# 使用 yum
yum clean all && yum makecache
 
 
# ubuntu 24.04
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
 
# ubuntu22.04
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
 
# ubuntu20.04
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

epel:

yum install epel-release
sed -e 's!^metalink= !#metalink= !g' \ -e 's!^#baseurl= !baseurl= !g' \
-e
's!https\?://download\.fedoraproject\.org/pub/epel!https://mirrors.tuna.tsinghua .edu.cn/epel!g' \
-e
's!https\?://download\.example/pub/epel!https://mirrors.tuna.tsinghua.edu.cn/epe l!g' \
-i /etc/yum.repos.d/epel{,-testing}.repo yum update
Document