最新Ubuntu内网源部署方法
1. 下载公网离线源
- 安装apt-mirror,并修改*/etc/apt/mirror.list内容,以ubuntu20.04*为例说明:
############# config ##################
#
#### !!!!!!!!!!此路径为离线源存储路径,保证空间足够!!!!!!!!!!
set base_path /home/chg/data/mirrors/ubuntu20.04
#
# 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-amd64、deb-i386!!!!!!!!!!
deb-amd64 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-i386 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-amd64 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-i386 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-amd64 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-i386 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-amd64 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-i386 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
#clean http://archive.ubuntu.com/ubuntu
-
(可选),apt-mirror常年缺乏维护,对新版本支持不佳(漏掉部分文件),
可以在本文链接下载apt-mirror,https://download.csdn.net/download/stacowt/79843148,
或在github上下载最新版本,感谢apt-mirror修复项目: https://github.com/Stifler6996/apt-mirrormv /usr/bin/apt-mirror /usr/bin/apt-mirror.ori cp apt-mirror /usr/bin/apt-mirror chmod 755 /usr/bin/apt-mirror
-
执行apt-mirror,耐心等待(200G左右大小)。
2. 部署离线源至服务器
- 将离线源拷贝至服务器,/home/xxx/mirrors/ubuntu20.04(该目录仅供参考,根据实际情况而定)。
#更改镜像源上级目录权限
chmod 755 /home/xxx/mirrors
-
服务器安装apache2服务,并设置防火墙
apt install -y apache2 ufw allow 'Apache' # 也可直接关闭防火墙
-
设置apache2离线源路径
cd /var/www/html ln -sf /home/xxx/mirrors/ubuntu20.04/mirror/mirrors.tuna.tsinghua.edu.cn/ubuntu ubuntu
-
启动apache2服务,并设置开机启动
systemctl start apache2 systemctl enable apache2
3. 内网使用方法
原sources.list中网址替换为服务器地址即可,以下为参考:
deb http://192.168.x.x/ubuntu/ focal main restricted universe multiverse
deb http://192.168.x.x/ubuntu/ focal-updates main restricted universe multiverse
deb http://192.168.x.x/ubuntu/ focal-backports main restricted universe multiverse
deb http://192.168.x.x/ubuntu/ focal-security main restricted universe multiverse