前言

在使用编程语言,开源软件,类UNIX系统时,我们常常会用到各类包管理器(Package-Manager)

eg:apt,yum,dnf,pip,pacman

而这些包管理器的源一般在各类网络镜像站.

但在实际生产环境时,我们往往需要使用公司内部的源.此时就需要搭建内网镜像站.

首先:搭建镜像站一共有三个步骤

1.确认上游镜像站

2.同步源

3.搭建服务器

1.确认上游镜像站

国内的上游镜像站非常多

这是各类高校的联合镜像站    校园网联合镜像站 (cernet.edu.cn)

2.同步源

首先我们要确定自己需要同步的源

接下来我们用到rsync工具

举几个例子

rsync -avPh rsync://上游镜像站/源/ /你的本地位置/

Debian源    

rsync -avPh rsync://mirrors.tuna.tsinghua.edu.cn/debian/ /media/user/disk/debian/

接下来是一些特殊用法

只同步源代码

rsync -avPh --include=*orig* --exclude=*.deb --exclude=*.tar.* --exclude=*.diff --exclude=*.dsc rsync://mirrors.tuna.tsinghua.edu.cn/debian/ /media/user/disk/src/

只同步特定架构的二进制软件包

rsync -avPh --include=*amd64.deb --include=*all.deb --exclude=*.deb --exclude=*.tar* rsync://mirrors.tuna.tsinghua.edu.cn/debian/ /本地/

3.搭建镜像站

搭建一个网页即可,例如nginx,apache2

apt update \
&& apt install -y apache2 \
&& systemctl start apache2.serivce \
&& ln -s /你的镜像目录 /var/www/html/ \
&& cp 你的镜像站主页.html /var/www/html/index.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐