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 是当前系统的版本代号
#运行下载,以后更新也可以运行这个指令
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
查看是否成功
#备份
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即可