news 2026/3/11 13:05:16

自建软件仓库

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
自建软件仓库

一,目的:

为了把网络软件仓库中的软件下载下来后分享给本地主机,或者直接把网上下载下来的rpm加入到软件仓库中,更高效便捷。搭建一个本地 HTTP 软件仓库,把 Docker 相关的 RPM 包下载下来存到仓库里,这样局域网里的其他主机就能通过 HTTP 访问这个仓库,直接安装 Docker,不用再去互联网上下载。

二,步骤:

1.准备 HTTP 服务(让其他机子能访问你的仓库,创建软件共享仓库)

[root@localhost ~]# dnf install httpd -y Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:07:35 ago on Thu 15 Jan 2026 07:39:41 AM EST. Dependencies resolved. ======================================================================================================= Package Architecture Version Repository Size ======================================================================================================= Installing: httpd x86_64 2.4.62-4.el9 AppStream 51 k Installing dependencies: apr x86_64 1.7.0-12.el9_3 AppStream 126 k apr-util x86_64 1.6.1-23.el9 AppStream 97 k apr-util-bdb x86_64 1.6.1-23.el9 AppStream 14 k httpd-core x86_64 2.4.62-4.el9 AppStream 1.5 M httpd-filesystem noarch 2.4.62-4.el9 AppStream 15 k httpd-tools x86_64 2.4.62-4.el9 AppStream 86 k redhat-logos-httpd noarch 90.4-2.el9 AppStream 18 k Installing weak dependencies: apr-util-openssl x86_64 1.6.1-23.el9 AppStream 17 k mod_http2 x86_64 2.0.26-4.el9 AppStream 167 k mod_lua x86_64 2.4.62-4.el9 AppStream 60 k Transaction Summary ======================================================================================================= Install 11 Packages Total size: 2.2 M Installed size: 6.1 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.7.0-12.el9_3.x86_64 1/11 Installing : apr-util-bdb-1.6.1-23.el9.x86_64 2/11 Installing : apr-util-openssl-1.6.1-23.el9.x86_64 3/11 Installing : apr-util-1.6.1-23.el9.x86_64 4/11 Installing : httpd-tools-2.4.62-4.el9.x86_64 5/11 Installing : redhat-logos-httpd-90.4-2.el9.noarch 6/11 Running scriptlet: httpd-filesystem-2.4.62-4.el9.noarch 7/11 Installing : httpd-filesystem-2.4.62-4.el9.noarch 7/11 Installing : httpd-core-2.4.62-4.el9.x86_64 8/11 Installing : mod_lua-2.4.62-4.el9.x86_64 9/11 Installing : mod_http2-2.0.26-4.el9.x86_64 10/11 Installing : httpd-2.4.62-4.el9.x86_64 11/11 Running scriptlet: httpd-2.4.62-4.el9.x86_64 11/11 Verifying : apr-1.7.0-12.el9_3.x86_64 1/11 Verifying : apr-util-1.6.1-23.el9.x86_64 2/11 Verifying : apr-util-bdb-1.6.1-23.el9.x86_64 3/11 Verifying : apr-util-openssl-1.6.1-23.el9.x86_64 4/11 Verifying : httpd-2.4.62-4.el9.x86_64 5/11 Verifying : httpd-core-2.4.62-4.el9.x86_64 6/11 Verifying : httpd-filesystem-2.4.62-4.el9.noarch 7/11 Verifying : httpd-tools-2.4.62-4.el9.x86_64 8/11 Verifying : mod_http2-2.0.26-4.el9.x86_64 9/11 Verifying : mod_lua-2.4.62-4.el9.x86_64 10/11 Verifying : redhat-logos-httpd-90.4-2.el9.noarch 11/11 Installed products updated. Installed: apr-1.7.0-12.el9_3.x86_64 apr-util-1.6.1-23.el9.x86_64 apr-util-bdb-1.6.1-23.el9.x86_64 apr-util-openssl-1.6.1-23.el9.x86_64 httpd-2.4.62-4.el9.x86_64 httpd-core-2.4.62-4.el9.x86_64 httpd-filesystem-2.4.62-4.el9.noarch httpd-tools-2.4.62-4.el9.x86_64 mod_http2-2.0.26-4.el9.x86_64 mod_lua-2.4.62-4.el9.x86_64 redhat-logos-httpd-90.4-2.el9.noarch Complete!

2.打开http服务

设置开机自启并立即启动服务,确保 HTTP 服务一直运行

[root@localhost ~]# systemctl enable --now httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

3.建立software目录,作为共享仓库的目录

[root@localhost ~]# mkdir /var/www/html/software

4.在/etc/yum.repos.d/下建立名为software.repo的仓库

[root@localhost yum.repos.d]# vim software.repo [software] name = software baseurl = http://192.168.110.129/software/ ***自己的IP!!! gpgcheck = 0

5.下载 Docker 相关 RPM 包

[root@localhost ~]# dnf install docker-ce --downloadonly --destdir /mnt/

只下载docker-ce及其所有依赖包,不安装,并且把下载的文件都放到/mnt目录里。

[root@localhost mnt]# mv /mnt/* /var/www/html/software/

把下载好的 RPM 包移动到刚才创建的 HTTP 共享目录里,这样其他主机就能通过 HTTP 访问到这些包了。

6.创建仓库元数据(让系统识别这是个软件仓库)

[root@localhost software]# dnf install createrepo -y [root@localhost ~]# createrepo -v /var/www/html/software/ 08:17:06: Version: 0.20.1 (Features: LegacyWeakdeps ) 08:17:07: Signal handler setup 08:17:07: Thread pool ready Directory walk started 08:17:07: Adding pkg: /var/www/html/software/containerd.io-2.2.1-1.el9.x86_64.rpm 08:17:07: Adding pkg: /var/www/html/software/docker-buildx-plugin-0.30.1-1.el9.x86_64.rpm 08:17:07: Adding pkg: /var/www/html/software/docker-ce-29.1.4-1.el9.x86_64.rpm 08:17:07: Adding pkg: /var/www/html/software/docker-ce-cli-29.1.4-1.el9.x86_64.rpm 08:17:07: Adding pkg: /var/www/html/software/docker-ce-rootless-extras-29.1.4-1.el9.x86_64.rpm 08:17:07: Adding pkg: /var/www/html/software/docker-compose-plugin-5.0.1-1.el9.x86_64.rpm 08:17:07: Dir to scan: /var/www/html/software/.repodata 08:17:07: Package count: 6 Directory walk done - 6 packages Temporary output repo path: /var/www/html/software/.repodata/ 08:17:07: Creating .xml.gz files 08:17:07: Setting number of packages Preparing sqlite DBs 08:17:07: Creating databases 08:17:07: Thread pool user data ready Pool started (with 5 workers) Pool finished 08:17:07: Generating repomd.xml 08:17:07: Old repodata doesn't exists: Cannot rename /var/www/html/software/repodata/ -> /var/www/html/software/repodata.old.31514.20260115081707.46238: cp: cannot stat '/var/www/html/software/repodata/': No such file or directory : Child process exited with code 1 08:17:07: Renamed /var/www/html/software/.repodata/ -> /var/www/html/software/repodata/ 08:17:07: Memory cleanup 08:17:07: All done [root@localhost ~]# cd /var/www/html/software/ [root@localhost software]# ls containerd.io-2.2.1-1.el9.x86_64.rpm docker-ce-rootless-extras-29.1.4-1.el9.x86_64.rpm docker-buildx-plugin-0.30.1-1.el9.x86_64.rpm docker-compose-plugin-5.0.1-1.el9.x86_64.rpm docker-ce-29.1.4-1.el9.x86_64.rpm repodata docker-ce-cli-29.1.4-1.el9.x86_64.rpm [root@localhost software]# cd [root@localhost ~]# cd /var/cache/dnf/ [root@localhost dnf]# ls AppStream-19fc8e1e0a4dd1ae BaseOS.solv epel-f0546a9ed4570b45 last_makecache AppStream-filenames.solvx docker-315377eead1481a2 epel-filenames.solvx packages.db AppStream.solv docker-filenames.solvx epel.solv tempfiles.json BaseOS-2133cde63ffc3a12 docker.solv epel-updateinfo.solvx BaseOS-filenames.solvx docker-updateinfo.solvx expired_repos.json [root@localhost dnf]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls docker.repo epel.repo redhat.repo rhel.repo [root@localhost yum.repos.d]# vim software.repo [root@localhost yum.repos.d]# dnf makecache Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. docker 5.1 kB/s | 2.0 kB 00:00 epel 14 kB/s | 4.0 kB 00:00 AppStream 3.1 MB/s | 3.2 kB 00:00 BaseOS 2.7 MB/s | 2.7 kB 00:00 software 602 kB/s | 4.9 kB 00:00 Metadata cache created. [root@localhost yum.repos.d]# ls /var/cache/dnf/ AppStream-19fc8e1e0a4dd1ae docker-filenames.solvx expired_repos.json AppStream-filenames.solvx docker.solv last_makecache AppStream.solv docker-updateinfo.solvx packages.db BaseOS-2133cde63ffc3a12 epel-f0546a9ed4570b45 software-4ded3c8cea30e088 *** BaseOS-filenames.solvx epel-filenames.solvx software-filenames.solvx *** BaseOS.solv epel.solv software.solv docker-315377eead1481a2 epel-updateinfo.solvx tempfiles.json

扫描rpm软件包信息并记录生成

create...在共享目录里生成元数据,这样其他主机的dnf/yum就能识别这个目录是一个合法的软件仓库

#采集软件包信息

#注意在目录中不能有不是rpm类的文件

关于createrepo:

createrepo是把一堆零散的 RPM 包,变成一个系统可识别的软件仓库的核心工具。


1. 核心作用

  • 生成仓库元数据:它会扫描你指定目录里的所有 RPM 包,分析每个包的名称、版本、依赖关系、文件列表等信息,然后生成一个叫repodata的目录。

  • dnf/yum能 “看懂” 仓库dnf/yum安装软件时,不会直接去一个个找 RPM 包,而是先读取repodata里的元数据,这样就能快速找到需要的包,自动解决依赖问题。


2. 举个例子

假设手动下载了docker-cecontainerd.io等几个 RPM 包,直接放在/var/www/html/software/目录里:

  • 没有createrepodnf不知道这些包之间的依赖关系,也无法识别这是一个合法仓库,会提示找不到包。

  • 用了createrepo:它会生成repodata目录,dnf读取这个目录后,就能知道 “这个仓库里有 Docker,安装它需要先装containerd.io”,然后自动帮你按顺序安装。


3. 工作原理

当你运行:

bash

运行

createrepo -v /var/www/html/software/

它会在/var/www/html/software/下生成一个repodata目录,里面包含:

  • primary.xml.gz:所有 RPM 包的基本信息(名称、版本、依赖等)

  • filelists.xml.gz:每个 RPM 包包含的文件列表

  • other.xml.gz:其他辅助信息(比如包的描述、变更日志)

  • repomd.xml:元数据的索引文件,dnf 会先读这个文件,再去解析其他元数据


7.查看验证文件是否存在

[root@localhost software]# ls containerd.io-2.2.1-1.el9.x86_64.rpm docker-ce-cli-29.1.4-1.el9.x86_64.rpm docker-buildx-plugin-0.30.1-1.el9.x86_64.rpm docker-ce-rootless-extras-29.1.4-1.el9.x86_64.rpm docker-ce-29.1.4-1.el9.x86_64.rpm docker-compose-plugin-5.0.1-1.el9.x86_64.rpm

cache的作用:

这一步是为了加速后续的软件安装、搜索操作,避免每次都去远程仓库重新下载元数据。


1. 核心作用

  • 下载并缓存仓库元数据dnf会从所有配置的.repo源里,下载仓库的元数据(比如包列表、依赖关系),然后把它们缓存到本地/var/cache/dnf/目录里。

  • 提升操作速度:之后你再执行dnf installdnf search等命令时,dnf直接读取本地缓存的元数据,不用每次都去远程仓库下载,速度会快很多。

  • 验证仓库配置:这也是一个验证仓库是否配置正确的好方法。如果执行dnf makecache后没有报错,并且能看到各个仓库的元数据都下载成功(比如你输出里的dockerepelsoftware仓库),说明你的.repo文件配置是有效的。


2. 结合你的场景理解

在你搭建本地 HTTP 仓库的流程里,执行dnf makecache主要是为了:

  1. 让系统识别新配置的software仓库:确保dnf能读取到你刚创建的本地仓库元数据。

  2. 避免后续安装时重复下载:缓存元数据后,后续安装 Docker 时,dnf直接从本地缓存获取依赖信息,不用每次都去 HTTP 仓库重新下载元数据。

  3. 提前发现仓库配置问题:如果software仓库的baseurl写错了,或者 HTTP 服务没启动,dnf makecache会立刻报错,这样你就能提前排查问题。

三,测试:

输入dnf info ... 命令可查看软件仓库

有以下结果即代表搭建共享仓库成功

[root@localhost yum.repos.d]# dnf info docker-ce.x86_64 Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:05:42 ago on Thu 15 Jan 2026 08:22:17 AM EST. Available Packages Name : docker-ce Epoch : 3 Version : 29.1.4 Release : 1.el9 Architecture : x86_64 Size : 22 M Source : docker-ce-29.1.4-1.el9.src.rpm Repository : docker Summary : The open-source application container engine URL : https://www.docker.com License : Apache-2.0 Description : Docker is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance : and everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider. Name : docker-ce Epoch : 3 Version : 29.1.4 Release : 1.el9 Architecture : x86_64 Size : 22 M Source : docker-ce-29.1.4-1.el9.src.rpm Repository : software Summary : The open-source application container engine URL : https://www.docker.com License : Apache-2.0 Description : Docker is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance : and everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider.

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/11 0:39:14

《创业之路》-865-如何利用下述分析方法找到并提前布局未来有爆发性潜力的公司:四阶价值流 × 商业模式画布 × 产品生命周期 × 创新 × 技术曲线 × 第二增长曲线 × 上中下游生态?

七维爆发力评估模型:提前布局未来10倍增长公司的实战指南核心理念:爆发性公司 技术曲线爬升期 价值流关键卡位 第二曲线已验证 生态位不可替代 最佳布局时点 技术低谷期(Gartner曲线"幻灭谷底") 主曲线达峰前2年一…

作者头像 李华
网站建设 2026/3/10 5:27:28

基于可变形自注意力的YOLOv11:目标检测性能优化实践

文章目录 **目标检测性能革新:基于可变形自注意力机制的YOLOv11深度优化实战** **第一章:解锁新一代视觉Transformer的核心——可变形自注意力** **第二章:从零构建——高效开发环境与数据准备** **第三章:核心技术实现——为YOLOv11注入“智能聚焦”模块** **第四章:模型…

作者头像 李华
网站建设 2026/3/10 6:30:36

mTOR(Ser2448)磷酸化如何揭示其信号网络的调控核心?

一、mTOR复合物如何作为细胞代谢与生长的中央控制器?哺乳动物雷帕霉素靶蛋白(mTOR)是一种在进化上高度保守的丝氨酸/苏氨酸蛋白激酶,它是细胞感知并整合营养、能量、生长因子及应激信号,进而调控细胞生长、增殖、自噬、…

作者头像 李华
网站建设 2026/3/11 0:39:09

SpringBoot 在一次 http 请求中耗费了多少内存?

SpringBoot 在一次 http 请求中耗费了多少内存?先说说为啥会关心这个问题先搞懂:一次 HTTP 请求,SpringBoot 到底在干啥?动手测:最简单的接口,到底耗多少内存?第一步:准备测试代码第…

作者头像 李华
网站建设 2026/3/11 0:39:08

商品评论分析|基于Python 商品评论分析系统(源码+数据库+文档)

商品评论分析 目录 基于PythonDjango商品评论分析系统 一、前言 二、系统功能演示 三、技术选型 四、其他项目参考 五、代码参考 六、测试参考 七、最新计算机毕设选题推荐 八、源码获取: 基于PythonDjango商品评论分析系统 一、前言 博主介绍&#xff1a…

作者头像 李华
网站建设 2026/3/8 3:09:07

AI健康管理|基于springboot AI健康管理系统(源码+数据库+文档)

AI健康管理 目录 基于springboot vueAI健康管理系统 一、前言 二、系统功能演示 三、技术选型 四、其他项目参考 五、代码参考 六、测试参考 七、最新计算机毕设选题推荐 八、源码获取: 基于springboot vueAI健康管理系统 一、前言 博主介绍&#xff1a…

作者头像 李华