下面给你几种在 Ubuntu 上搭建本地镜像(仓库镜像)的常见方案,从最简单到企业级,你可以按需求选择。
常见类型:
下面以 APT 软件源镜像 为主讲。
sudo apt update
sudo apt install apt-mirror -y
编辑配置文件:
sudo vim /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
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
sudo apt-mirror
⚠️ 完整 Ubuntu 源非常大(几百 GB),建议只镜像需要的架构和版本
sudo apt install nginx -y
sudo vim /etc/nginx/sites-enabled/mirror.conf
server {
listen 80;
server_name mirror.local;
root /mirror/mirror/archive.ubuntu.com;
autoindex on;
location / {
try_files $uri $uri/ =404;
}
}
sudo systemctl restart nginx
sudo sed -i 's|http://archive.ubuntu.com|http://mirror.local|g' /etc/apt/sources.list
sudo apt update
适合:
sudo apt install reprepro -y
mkdir -p /srv/repo/ubuntu/{conf,incoming}
conf/distributions 示例:
Origin: MyRepo
Label: MyRepo
Codename: jammy
Architectures: amd64
Components: main
Description: Local Ubuntu Repo
导入 deb 包:
reprepro -b /srv/repo/ubuntu includedeb jammy xxx.deb
sudo apt install apt-cacher-ng -y
客户端:
Acquire::http::Proxy "http://mirror:3142";
✅ 好处:
0 3 * * * /usr/bin/apt-mirror
| 需求 | 推荐方案 |
|---|---|
| 内网 apt 加速 | apt-cacher-ng |
| 全量 Ubuntu 镜像 | apt-mirror |
| 私有软件分发 | reprepro |
| 简单文件服务 | nginx |
如果你告诉我:
我可以给你可直接用的完整配置。