在 Ubuntu 上搭建**本地镜像(Local Mirror)**通常用于:
下面按常见需求给你几种方案,从简单到完整。
apt-mirror(经典方案)sudo apt update
sudo apt install apt-mirror
编辑:
sudo nano /etc/apt/mirror.list
示例(Ubuntu 22.04):
set base_path /mirror
set mirror_path $base_path/mirror
set skel_path $base_path/skel
set var_path $base_path/var
set defaultarch amd64
set nthreads 20
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
sudo apt-mirror
sudo apt install nginx
sudo ln -s /mirror/mirror/archive.ubuntu.com/ubuntu /var/www/html/ubuntu
deb http://你的IP/ubuntu jammy main restricted universe multiverse
rsync(官方镜像方式)⚠️ 数据量大(几百 GB 起)
rsync -avz --delete \
rsync://archive.ubuntu.com/ubuntu/ \
/mirror/ubuntu/
适合:
apt-cacher-ng只缓存已下载过的包
sudo apt install apt-cacher-ng
客户端配置:
Acquire::http::Proxy "http://镜像服务器:3142";
优点:
sudo mount -o loop ubuntu-22.04.iso /mnt
deb file:/mnt jammy main restricted
| 场景 | 推荐 |
|---|---|
| 内网加速 | apt-cacher-ng |
| 完整镜像 | apt-mirror / rsync |
| 离线装机 | ISO + apt-mirror |
| 私有云 | apt-mirror + nginx |
如果你告诉我:
我可以帮你直接写好一份可执行的配置。