使用 apt-mirror创建Ubuntu镜像
时间:2020-02-23 14:45:25 来源:igfitidea点击:
在此简短的教程中,将介绍如何使用apt-mirror设置本地Ubuntu存储库镜像。
当我们在网络中有很多Ubuntu服务器时,这通常会派上友好。
什么是apt-mirror?
这是一个小型工具,可提供镜像任何零件(甚至全部)Debian和Ubuntu GNU/Linux发行版或者任何其他由开源开发人员提供的任何其他APT源的能力。
本教程将介绍为Ubuntu 16.04和Ubuntu 14.04设置的存储库镜像。
安装程序将类似于Ubuntu 12.04和17.04.
安装apt-mirror
apt-get install apt-mirror
配置apt-mirror
安装apt-mirror后,我们现在可以继续执行一些配置。
这意味着添加存储库URL。
打开文件/etc/apt/mirror.list
vim /etc/apt/mirror.list
修改下面的文件,将官方Ubuntu镜像同步16.04和14.04到网络。
要同步Ubuntu 16.04,请将以下行添加到文件中。
deb-amd64 http://archive.ubuntu.com/ubuntu xenial main main/debian-installer main/installer-amd64 main/i18n main/source restricted restricted/debian-installer universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu xenial main main/debian-installer main/installer-i386 main/i18n main/source restricted restricted/debian-installer universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
要同步Ubuntu 14.04,请将以下行添加到文件中。
deb-amd64 http://archive.ubuntu.com/ubuntu trusty main main/debian-installer main/installer-amd64 main/i18n main/source restricted restricted/debian-installer universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse deb-amd64 http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu trusty main main/debian-installer main/installer-i386 main/i18n main/source restricted restricted/debian-installer universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse deb-i386 http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
这将适用于32位和64位Ubuntu系统。
写日常运行的Cron作业以自动执行SYNC:
50 3 * * * /usr/bin/apt-mirror
我们可以手动调用apt-mirror命令,并启动同步。
/usr/bin/apt-mirror
使用nginx服务存储库:
apt-get install nginx systemctl enable nginx systemctl start nginx vim /etc/nginx/conf.d/mirrors.conf
内容应该如下所示:
server { listen 80; server_name domain.com; root /var/mirrors/apt-mirror/mirror/archive.ubuntu.com; location/{ autoindex on; } }
重新启动nginx.
systemctl restart nginx
配置客户端
Ubuntu 16.04
vim /etc/apt/sources.list
添加:
#------------------------------------------------------------------------------# # OFFICIAL UBUNTU REPOS # #------------------------------------------------------------------------------# ###### Ubuntu Main Repos deb http://domain.com/ubuntu/xenial main restricted universe multiverse ###### Ubuntu Security Repos deb http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse ###### Ubuntu Update Repos deb http://domain.com/ubuntu/xenial-updates main restricted universe multiverse deb http://domain.com/ubuntu/xenial-backports main restricted universe multiverse
Ubuntu 14.04.
#------------------------------------------------------------------------------# # OFFICIAL UBUNTU REPOS # #------------------------------------------------------------------------------# ###### Ubuntu Main Repos deb http://domain.com/ubuntu/trusty main restricted universe multiverse ###### Ubuntu Security Repos deb http://security.ubuntu.com/ubuntu trusty-security main restricted universe multiverse ###### Ubuntu Update Repos deb http://domain.com/ubuntu/trusty-updates main restricted universe multiverse deb http://domain.com/ubuntu/trusty-backports main restricted universe multiverse
opt更新:
apt-get update