系统环境为 Ubuntu 18.04,搭建支持 Ubuntu 系和 CentOS 系的双私有软件仓库。
Ubuntu 本地软件镜像源使用 apt-mirror 工具与远程仓库同步,CentOS 本地镜像源使用 reposync 工具与远程仓库同步。
上述两个工具都可以通过 Ubuntu 的包管理器 apt-get 命令直接安装使用。
一、环境准备
我这里搭建了 Ubuntu 18.04、Ubuntu 16.04 和 CentOS7 三个镜像源,从远程仓库拉取的软件包总共耗费了约 300G 硬盘空间,其中两个 Ubuntu 占用了约 261G,CentOS7(包含 epel 源)约 29G 。
创建镜像源前需保证本地有足够的存储空间。
建议给磁盘分区时使用 LVM(逻辑卷管理) 的方式,便于之后对存储空间进行扩容等操作。
关于 Linux 系统磁盘分区和 LVM 的介绍可以参考 Linux 磁盘设备和 LVM 管理命令详解。此处不作赘述。
安装同步工具:
$ sudo apt-get install apt-mirror reposync createrepo
安装 web 服务器(nginx):
$ sudo apt-get install nginx
二、Ubuntu 镜像源搭建
编辑 /etc/apt/mirror.list 配置文件,修改远程仓库的地址为国内的阿里镜像站,本地的 Ubuntu 软件仓库将定期从阿里源同步软件包。
set nthreads 20
set _tilde 0
set base_path /opt/mirrors/ubuntu
set defaultarch amd64
#Ubuntu 16.04
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
#Ubuntu 18.04
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
clean http://mirrors.aliyun.com/ubuntu
上述配置文件中 base_path 指定的