Ubuntu20.04搭建本地镜像服务器

Ubuntu20.04搭建本地镜像服务器

  • 安装镜像下载工具
#更新安装
apt update
apt install apt-mirror
  • 修改配置文件来更改下载源
vim /etc/apt/mirror.list
mirror.list
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# set mirror_path $base_path/mirror
# set skel_path $base_path/skel
# set var_path $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb http://cn.archive.ubuntu.com/ubuntu focal main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
 
clean http://cn.archive.ubuntu.com/ubuntu

这里的 focal 是当前系统的版本代号

  • 配置完后下载镜像文件 (大约150GB)
#运行下载,以后更新也可以运行这个指令
apt-mirror

下载完毕后,所有的文件在/var/spool/apt-mirror/mirror/cn.archive.ubuntu.com/ubuntu/目录下

  • 外部网络访问
#安装apache2
apt install apache2

#在/var/www/html中创建软连接
ln -s /var/spool/apt-mirror/mirror/cn.archive.ubuntu.com/ubuntu/ /var/www/html/ubuntu

#启动服务
systemctl start apache2

访问http://[host]:[port]/ubuntu查看是否成功

  • 修改apt源
#备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak

#修改
vim /etc/apt/sources.list

#更新
apt update
sources.list
deb http://192.168.200.154:50002/ubuntu focal main restricted
deb http://192.168.200.154:50002/ubuntu focal-updates main restricted
deb http://192.168.200.154:50002/ubuntu focal universe
deb http://192.168.200.154:50002/ubuntu focal-updates universe
deb http://192.168.200.154:50002/ubuntu focal multiverse
deb http://192.168.200.154:50002/ubuntu focal-updates multiverse
deb http://192.168.200.154:50002/ubuntu focal-backports main restricted universe multiverse
deb http://192.168.200.154:50002/ubuntu focal-security main restricted
deb http://192.168.200.154:50002/ubuntu focal-security universe
deb http://192.168.200.154:50002/ubuntu focal-security multiverse

以上步骤操作完后,执行apt update会有报错,因为这个apt-mirror没有维护并且有几个错误,新版本缺少文件。

解决办法:拉取 https://github.com/Stifler6996/apt-mirror ,并将apt-mirror替换掉/usr/bin内的apt-mirror

最后重新执行apt-mirror即可

    原文作者:LeiYu_lf
    原文地址: https://blog.csdn.net/qq_38640700/article/details/120178265
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞