本文向你展示如何使用apt-mirror设置本地Ubuntu存储库镜像,当你的网络中有大量的Ubuntu服务器时,这通常会派上用场,以下操作在root用户中进行。
apt-mirror简介
它是一个小工具,可以镜像Debian和Ubuntu GNU/Linux发行版的任何部分(甚至全部)或通常由开源开发人员提供的任何其他apt源。
本文将介绍如何为Ubuntu 16.04和Ubuntu 14.04设置存储库镜像,其它的Ubuntu版本,如18.04设置类似,请自行更改源地址。
安装apt-mirror
apt-get install apt-mirror
配置apt-mirror
安装apt-mirror后,我们现在可以继续进行一些配置了,这意味着添加存储库URL。
打开文件/etc/apt/mirror.list:
vim /etc/apt/mirror.list
修改如下所示的文件,将16.04和14.04的官方Ubuntu镜像同步到你的网络。
要同步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作业以自动执行同步:
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
然后运行以下命令更新即可达到目的:
apt-get update
相关主题