当前位置: 首页 > news >正文

ubuntu24.04制作离线本地APT源

目录

  • 一、服务端替换APT公共源
  • 二、安装apt-mirror
  • 三、同步软件包
  • 四、代理本地软件包目录
  • 五、客户端修改本地离线APT源
  • 六、定时同步公共源软件包

一、服务端替换APT公共源

介绍有两种方式,但方法一和方法二无需同时配置,否则apt update时会提示存在重复的软件源配置,建议使用方法一。此外,我在配置完apt update时报错 403 Forbidden,找阿里云提单放通我的公网IP就好了,但还是会有限速,实际可替换为其他源。
Ubuntu20.04和Ubuntu22.04制作本地离线APT源可参考以下链接,方法都是类似的
https://blog.csdn.net/weixin_44758063/article/details/139750386?spm=1001.2014.3001.5501
1、方法一
修改/etc/apt/sources.list文件

cp /etc/apt/sources.list /etc/apt/sources.list.backup
vi /etc/apt/sources.list

打开文件其实可以看到官方提示源配置已经移到了另一个配置文件,但是修改这里其实还是可以生效的
在这里插入图片描述

deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse

2、方法二
修改/etc/apt/sources.list.d/ubuntu.sources文件

Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpgTypes: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

URIs:后面链接修改为 https://mirrors.aliyun.com/ubuntu/

二、安装apt-mirror

上面两种方法选择其一之后,更新源,安装软件

apt update
apt upgrade -y
apt install apt-mirror

挂载磁盘
给虚拟机新建了一块800G磁盘,要下载的文件有600GB以上。

mkfs.xfs /dev/vdb
mkdir /apt-ubuntu24.04
mount /dev/vdb /apt-ubuntu24.04
echo "/dev/vdb /apt-ubuntu24.04 xfs	defaults,nofail	0 0" >> /etc/fstab
mount -a

三、同步软件包

编辑 apt-mirror 配置文件 /etc/apt/mirror.list,添加以下内容。

cp /etc/apt/mirror.list /etc/apt/mirror.list.bak
vi /etc/apt/mirror.list

set base_path /apt-ubuntu24.04 本地下载保存路径
set defaultarch amd64 系统处理器架构
set nthreads 20 20线程下载
同时这里有个注意事项,链接https://mirrors.aliyun.com/ubuntu后不要接/符号,否则apt-mirror时会有报错(如 can’t open index)并且下载不全。

############# config ##################
#
set base_path    /apt-ubuntu24.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  amd64
set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############
deb https://mirrors.aliyun.com/ubuntu noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble-security main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble-updates main restricted universe multiverse# deb https://mirrors.aliyun.com/ubuntu noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu noble-proposed main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble-backports main restricted universe multiverseclean https://mirrors.aliyun.com/ubuntu

开始同步,看提示有618.5G要下载,耐心等待同步完成。全量同步 600GB + 文件耗时较长(100Mbps 网速约需 14 小时,1Gbps 约需 1.5 小时)。

apt-mirror

在这里插入图片描述
有时会有下载中断的情况导致下载不全,需要多次执行apt-mirror,中断后再执行命令会从已完成部分继续,不会从头开始。直到出现0 bytes will be downloaded into archive.说明文件已全部下载完成。

apt-mirror
apt-mirror

在这里插入图片描述

四、代理本地软件包目录

下载完成后,软件包和依赖包将会存储在 /apt-ubuntu24.04/ 目录下。
需要代理的目录为当前同步源下/ubuntu目录,即/apt-ubuntu24.04/mirror/mirrors.aliyun.com/ubuntu/

apt install -y apache2
cd /var/www/html/
ln -sf /apt-ubuntu24.04/mirror/mirrors.aliyun.com/ubuntu/ ubuntu24.04

五、客户端修改本地离线APT源

配置客户端来使用服务端10.17.16.199的apt源。使用以下命令编辑/etc/apt/sources.list文件:

deb http://10.17.16.199/ubuntu24.04 noble main restricted universe multiverse
deb-src http://10.17.16.199/ubuntu24.04 noble main restricted universe multiversedeb http://10.17.16.199/ubuntu24.04 noble-security main restricted universe multiverse
deb-src http://10.17.16.199/ubuntu24.04 noble-security main restricted universe multiversedeb http://10.17.16.199/ubuntu24.04 noble-updates main restricted universe multiverse
deb-src http://10.17.16.199/ubuntu24.04 noble-updates main restricted universe multiverse# deb http://10.17.16.199/ubuntu24.04 noble-proposed main restricted universe multiverse
# deb-src http://10.17.16.199/ubuntu24.04 noble-proposed main restricted universe multiversedeb http://10.17.16.199/ubuntu24.04 noble-backports main restricted universe multiverse
deb-src http://10.17.16.199/ubuntu24.04 noble-backports main restricted universe multiverse
apt update

在这里插入图片描述
配置完成,客户端就可以使用刚才创建的本地APT源来下载软件包。

六、定时同步公共源软件包

每周六凌晨3点执行apt-mirror,日志输出到 /var/log/apt-mirror/cron.log

mkdir -p /var/log/apt-mirror
chmod 755 /var/log/apt-mirror
crontab -e
0 3 * * 6 nohup /usr/bin/apt-mirror > /var/log/apt-mirror/cron.log 2>&1 &

在这里插入图片描述

内网服务器到外网的权限不宜过大,但现在的防火墙一般都支持URL过滤,服务端服务器申请到https://mirrors.aliyun.com/ubuntu网址,端口80、443的公网访问权限就可以了。

http://www.dtcms.com/a/573794.html

相关文章:

  • UDS诊断服务基础详解之十四—85服务
  • 神经符号模型与增量学习——下一代可控人工智能的正统新范式
  • 企业官方网站开发如何入账做交通分析的网站
  • 如何使用爱站网婚庆网站建设公司
  • 高职大数据技术专业学习与发展指南
  • 上海网站建设的网站crm客户关系管理论文
  • C++的时间陷阱——临时对象、引用折叠与生命周期延长
  • 关于unity世界坐标和相对坐标
  • 企业网站建设研究凡科互动永久解封
  • 专做排名的网站做漫画网站
  • 数据库 连接工具 免费
  • 魔云手机建站商务网站规划建设与管理答案
  • django中request.GET.urlencode的使用
  • 优秀网站设计重庆网站营销
  • 孟村县网站建设通州网站建设是什么
  • Qt解决_mm_loadu_si64找不到标识符问题
  • 灾难恢复(DR):RTO/RPO 定义、冷备/热备/双活架构
  • 台州网站设计 解放路成都网站开发哪家好
  • 吉林网络公司哪家好如何做好seo基础优化
  • 芜湖有哪些招聘网站企业网站优化问题
  • 借助 Kiro:实现《晚间手机免打扰》应用,破解深夜刷屏困境
  • Apache DolphinScheduler 3.3.2 正式发布!性能与稳定性有重要更新
  • 视频网站开发技术书糕点网站设计
  • 站点和网页的关系移动网站建设哪家好
  • Linux进程调度与Nice值完全指南:从新手到精通
  • Hadess零基础学习,如何管理Go制品
  • 贷中风控策略:分群、支用、调额、调价、预警...
  • STM32单片机 IIC 通信协议
  • 旅游平台网站合作建设方案微信h5的制作方法
  • Spring Boot3零基础教程,响应式编程,前景提要,笔记108