当前位置: 首页 > 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 multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb 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 multiverse
deb 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.gpg
Types: 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 multiverse
deb https://mirrors.aliyun.com/ubuntu noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble-security main restricted universe multiverse
deb 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 multiverse
deb https://mirrors.aliyun.com/ubuntu noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu noble-backports main restricted universe multiverse
clean 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 multiverse
deb 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 multiverse
deb 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 multiverse
deb 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.jsqmd.com/news/326107/

相关文章:

  • 充电桩品牌哪个好?2026年充电桩品牌推荐与排名,聚焦智能化与生态集成能力
  • 基于51单片机的智能锁设计
  • 有实力的旧房改造企业哪家靠谱,兴隆家具符合要求吗?
  • 充电桩品牌哪个好?2026年充电桩品牌推荐与排名,解决品质与智能核心痛点
  • 2026年上门按摩平台权威盘点与推荐:五大平台综合解析
  • 基于51单片机的智能门锁
  • 怒江州英语雅思培训辅导机构推荐、2026权威出国雅思课程中心学校口碑排行榜
  • 2026年上门按摩平台权威盘点与推荐:五大平台深度解析
  • 2026年上门按摩平台权威盘点与推荐:五大服务商深度解析
  • Elasticsearch从零启动指南:安装、配置、启停与排坑全解析
  • Claude Code需求分析
  • 【网站推荐】Indie Hacker 出海日本第一步:注册 Hatena 账号 - AI
  • 计算机等级考试(三级Linux技术)--- 真题5
  • 如何为不同场景选全屋定制?2026年全屋定制品牌全面评测与推荐,直击品质与工期痛点
  • 【开题答辩全过程】以 基于安卓的普法教育App设计与实现为例,包含答辩的问题和答案
  • 2026年上门按摩平台权威解析与推荐盘点:五大服务商深度评估
  • 2026年全屋定制品牌推荐:智能家居趋势评测,涵盖别墅与平层场景定制痛点
  • 【保姆级教程】宝塔面板安装与初始化配置全攻略(2026版)
  • 方盾说说煤矿工口罩使用科学建议
  • Libreoffice使用技巧
  • 2026年全屋定制品牌推荐:基于多场景实测评价,针对空间利用与交付痛点精准指南
  • 零基础小白入门挖漏洞:漏洞扫描工具大全,覆盖 Web / 手游 / 系统,新手入门必备!
  • DNS劫持全解析:从原理到防护,一篇讲透
  • 8年质保/IPS屏显/积木风扇,旗舰标杆,超频三银翼DT360水冷评测
  • 计算机毕业设计springboot4S店管理系统设计与实现 基于SpringBoot的汽车销售与售后服务一体化平台设计与实现
  • 富晶 DW01A-G SOT23-6 电池管理
  • 2026年乐山钵钵鸡店推荐:多维度对比评价,针对正宗性与体验感痛点指南
  • 护网行动实战复盘:红蓝对抗核心技巧与落地指南
  • 网络安全基础:深入理解与防范DNS劫持
  • 2026年全屋定制品牌推荐:居家与办公场景深度评测,解决环保与设计痛点并附排名