使用 apt-mirror 创建 Ubuntu 镜像使用 apt-mirror 创建 Ubuntu 镜像使用 apt-mirror 创建 Ubuntu 镜像使用 apt-mirror 创建 Ubuntu 镜像
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

使用 apt-mirror 创建 Ubuntu 镜像

发表 admin at 2025年2月28日
类别
  • 未分类
标签

使用 apt-mirror 创建 Ubuntu 镜像:大家好。在这个简短的教程中,我将向您展示如何使用 apt-mirror 设置本地 Ubuntu 存储库镜像。当您的网络中有大量 Ubuntu 服务器时,这通常会派上用场。

什么是 apt-mirror?

这是一个小工具,能够镜像 Debian 和 Ubuntu GNU/Linux 发行版的任何部分(甚至全部)或通常由开源开发人员提供的任何其他 apt 源。

本指南将介绍为 Ubuntu 设置存储库镜像。类似的过程适用于 Ubuntu Linux 的任何其他版本。

在 Ubuntu 上安装 apt-mirror

安装要求:

  • 更新操作系统
  • 足够的空间。您可以将辅助磁盘挂载到/var/spool/apt-mirror(存储库内容存储路径)

更新包存储库索引

sudo apt update

然后安装 apt-mirror 包:

sudo apt install apt-mirror

在 Ubuntu 上配置 apt-mirror

安装完apt-mirror后,我们现在可以继续进行一些配置。这意味着添加存储库 URL。

打开文件 /etc/apt/mirror.list

sudo vim /etc/apt/mirror.list

修改如下文件,将 22.04/20.04/18.04 的官方 Ubuntu 镜像同步到您的网络。

要同步 Ubuntu 22.04,请将以下行添加到文件中。

deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu jammy-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse

要同步 Ubuntu 20.04,请将以下行添加到文件中。

deb http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse

要同步 Ubuntu 18.04,请将以下行添加到文件中。

deb http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse

这适用于 32 位和 64 位 Ubuntu 系统。

手动启动同步

您也可以手动调用 apt-mirror 命令来启动同步。

sudo /usr/bin/apt-mirror

执行输出示例:

Downloading 340 index files using 20 threads...
Begin time: Tue Jan 18 18:44:40 2022
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Tue Jan 18 18:44:41 2022

Processing translation indexes: [TTTTTTTT]

Downloading 567 translation files using 20 threads...
Begin time: Tue Jan 18 18:44:41 2022
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Tue Jan 18 18:44:42 2022

Processing DEP-11 indexes: [DDDDDDDD]

Downloading 104 dep11 files using 20 threads...
Begin time: Tue Jan 18 18:44:42 2022
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Tue Jan 18 18:44:42 2022

Processing indexes: [SSSSPPPPPPPP]
........

使用 cron 作业自动同步包

编写每天运行的 cron 作业以自动进行同步:

$ sudo crontab -e
50 3  * * * /usr/bin/apt-mirror

使用 nginx 为存储库提供服务:

安装 Nginx 网络服务器:

sudo apt update
sudo apt install nginx

启动并启用服务:

sudo systemctl enable nginx
sudo systemctl start nginx

配置 Nginx 来为 Ubuntu 存储库提供服务:

sudo vim /etc/nginx/conf.d/mirrors.conf

内容应类似于以下内容:

server {
 listen 80;
 server_name mirror.domain.com; 
 root /var/spool/apt-mirror/mirror/archive.ubuntu.com/;

 location / {
   autoindex on;
 }
}

重启nginx

sudo systemctl restart nginx

配置客户端以使用配置的镜像

我们将使用 Ubuntu 20.04 作为客户端计算机配置的示例。

编辑默认源配置文件:

sudo vim /etc/apt/sources.list

将存储库设置为已配置的存储库。

#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#

###### Ubuntu Main Repos
deb http://mirror.domain.com/ubuntu/ focal main restricted universe multiverse

###### Ubuntu Security Repos
deb http://mirror.domain.com/ubuntu focal-security main restricted universe multiverse

###### Ubuntu Update Repos
deb http://mirror.domain.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirror.domain.com/ubuntu/ focal-backports main restricted universe multiverse

测试配置的存储库是否正常工作:

sudo apt update

请参阅以下更多文章:

  • 购买带 VLAN 的廉价以太网千兆交换机
  • 8 款配备英特尔第 11 代 CPU 的最佳笔记本电脑
  • 5 个便宜的 iPhone 快速无线充电器支架
©2015-2025 Norria support@alaica.com