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即可

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值