安装 apt-mirror

sudo apt install apt-mirror
sudo vi /etc/apt/mirror.list

参考以下配置文件:(清空原有的配置文件,直接使用以下配置文件即可)

############# config ##################
# 以下注释的内容都是默认配置,如果需要自定义,取消注释修改即可
set base_path /var/spool/apt-mirror
#
# 镜像文件下载地址
# set mirror_path $base_path/mirror
# 临时索引下载文件目录,也就是存放软件仓库的dists目录下的文件(默认即可)
# set skel_path $base_path/skel
# 配置日志(默认即可)
# set var_path $base_path/var
# clean脚本位置
# set cleanscript $var_path/clean.sh
# 架构配置,i386/amd64,默认的话会下载跟本机相同的架构的源
set defaultarch amd64
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
# 下载线程数
set nthreads 20
set _tilde 0
#
############# end config ##############
# Ali yun(这里没有添加deb-src的源)
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
 
clean http://mirrors.aliyun.com/ubuntu

同步

sudo apt-mirror

然后等待很长时间 , 同步的镜像文件目录为 /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu/ , 如果增加了其他的源,在 /var/spool/apt-mirror/mirror 目录下还有其他的地址为名的目录

注意:当 apt-mirror 被意外中断时,只需要重新运行即可,apt-mirror 支持断点续存;另外,意外关闭,需要在 /var/spool/apt-mirror/var 目录下面删除 apt-mirror.lock 文件【 sudo rm apt-mirror.lock 】,之后执行 apt-mirror 重新启动

sudo rm /var/spool/apt-mirror/var/apt-mirror.lock

外部网络访问

安装 apache2

sudo apt install apache2

Apache2 的默认网页文件目录位于 /var/www/html,可做个软链接(这样我们就可以直接访问了,无需将其直接导入该目录)

sudo ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu

客户端配置

编辑 /etc/apt/source.list,加入以下内容

# Local Source      #ip和port是自己本机的,其中端口默认为80
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-security main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-updates main restricted universe multiverse  
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-backports main restricted universe multiverse

更新 apt-get 源

apt update

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注