AlmaLinux 9:离网装包与架构核对
本文在 almalinux:9 容器(AlmaLinux 9.8,aarch64,dnf 4.14.0)中实际执行:createrepo_c 安装、dnf install --downloadonly --destdir=… tree、rpm -qp --qf 查包架构、createrepo_c 建元数据、写本地 repo 后 --disablerepo="*" --enablerepo=local-offline install tree、rpm -q tree,以及「下载后再装别的包」的复现。日志:plans/content-expansion/evidence/logs/alma-offline-updates.log。
依赖解析的完整链路、GPG 签名校验、以及真实离网机器的网络隔离未在本环境验证,文中按需标注。
第一步:先核对架构,别把包搬错
Section titled “第一步:先核对架构,别把包搬错”uname -mrpm -qp --qf "%{NAME} %{ARCH} %{VERSION}\n" /srv/off2/*.rpmaarch64tree aarch64 1.8.0离线装包最常见的失败不是「没建仓库」,而是架构或大版本不匹配:在有网机器上抓到 x86_64 的包,搬到 aarch64 的机器上装不了。先对一遍 uname -m 与 rpm -qp 的输出,再谈后面。
第二步:暂存包到 staging 目录
Section titled “第二步:暂存包到 staging 目录”sudo dnf -y install --downloadonly --destdir=/srv/off2 treels /srv/off2tree-1.8.0-10.el9.aarch64.rpm这一步之后不要急着装别的包。本次实测:接着执行 dnf -y install wget,再看 /srv/off2 已经空了——dnf 在下一个成功事务后清理了暂存目录。先把 createrepo_c 等工具装好,再执行 --downloadonly。
第三步:建元数据并指向目录
Section titled “第三步:建元数据并指向目录”sudo createrepo_c /srv/off2printf '[local-offline]\nname=Local offline\nbaseurl=file:///srv/off2\nenabled=1\ngpgcheck=0\n' \ | sudo tee /etc/yum.repos.d/local-offline.reposudo dnf clean allcreaterepo_c 生成 repodata/,dnf 才把这个目录当仓库;没有它,放再多 rpm 也只会得到 No match for argument。
第四步:只启用本地源安装
Section titled “第四步:只启用本地源安装”sudo dnf -y --disablerepo="*" --enablerepo=local-offline install treerpm -q treeInstalled: tree-1.8.0-10.el9.aarch64Complete!tree-1.8.0-10.el9.aarch64离网机器上其他源都不可达,--disablerepo="*" 能避免卡在超时。
第五步:离网验收(比「装上了」更重要)
Section titled “第五步:离网验收(比「装上了」更重要)”rpm -q treerpm -V treednf --disablerepo="*" --enablerepo=local-offline repoquery --requires tree | headrpm -q 有版本、rpm -V 无输出(文件未被改动)、依赖查询能列出来,三条都过才算这次交付可用。依赖是否全部满足要以实际安装结果为准:本次 tree 无额外依赖,换 nginx 这类包时要确认下载时把依赖一起抓了下来。
- 抓错架构:先
uname -m再下载,aarch64与x86_64的包互不相容; - 建库前先装了别的包:暂存目录会被清空(本文实测),顺序是「装工具 → 下载 → 建库」;
gpgcheck=0长期留在生产:离网环境也应带 AlmaLinux 的 GPG key,用gpgcheck=1+ 本地gpgkey=file://校验。
练习:把 nginx 搬到离网机
Section titled “练习:把 nginx 搬到离网机”前置:有网机器 A、离网机器 B,架构相同、均为 AlmaLinux 9。
# Asudo dnf -y install createrepo_csudo dnf -y install --downloadonly --destdir=/srv/off nginxsudo createrepo_c /srv/offtar -C /srv -czf off.tgz off# Bsudo tar -C /srv -xzf off.tgz# local-offline.repo 指向 /srv/off 后:sudo dnf -y --disablerepo="*" --enablerepo=local-offline install nginx检查:
rpm -q nginx→ 有版本rpm -V nginx→ 无输出dnf --disablerepo="*" --enablerepo=local-offline repoquery --requires nginx | wc -l→ 依赖数量与 A 机器dnf repoquery --requires nginx | wc -l一致
常见问题
为什么本地仓库里明明有 rpm,dnf 却说 No match?
多半是没有 repodata:目录只是普通文件夹。先在目录里跑 createrepo_c,再 dnf clean all 让它重新读元数据。
下载完包,过一会儿文件不见了?
本次实测里,下载后再执行任何成功的 dnf 事务(例如装 wget),暂存目录会被清理。先装好 createrepo_c 等工具,再做 --downloadonly。
离网机器要不要开 gpgcheck?
建议开。把 AlmaLinux 的 GPG 公钥一起带过去,repo 里写 gpgcheck=1 与 gpgkey=file:///...;长期 gpgcheck=0 等于放弃签名校验。
- 仓库与 SIG 变体:AlmaLinux 仓库
- 事务回滚:dnf history undo
- 多仓库冲突(页面待补):
/repo-priority/