目标与适用场景
架构与准备
部署步骤
sudo apt update && sudo apt install -y apt-mirror apache2sudo vim /etc/apt/mirror.list############# config ##################
set base_path /var/spool/apt-mirror
set nthreads 20
set _tilde 0
############# end config ##############
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# 可选:backports、proposed
# deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
clean https://mirrors.aliyun.com/ubuntu/
sudo apt-mirrorsudo ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu/ /var/www/html/ubuntusudo systemctl enable --now apache2客户端配置与使用
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakdeb http://<服务器IP>/ubuntu/ focal main restricted universe multiverse
deb http://<服务器IP>/ubuntu/ focal-updates main restricted universe multiverse
deb http://<服务器IP>/ubuntu/ focal-security main restricted universe multiverse
# 可选
# deb http://<服务器IP>/ubuntu/ focal-backports main restricted universe multiverse
sudo apt updatesudo apt install -y tree(或其他小包),观察下载是否来自 <服务器IP>。自动化与维护
sudo vim /etc/cron.d/apt-mirror0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log 2>&1
sudo /var/spool/apt-mirror/var/clean.sh(由 apt-mirror 生成的清理脚本)。常见问题与优化
sudo apt clean && sudo apt update。