CentOS 7停服(EOL)后如何下载RPM包

8824 2025-11-27 18:06:08
CentOS 7已于2024年06月30日停止维护,一些常用的RPM包查找网站也逐渐不再支持对CentOS 7 RPM包的检索,目前还有不少产品依然在使用该版本,那么基

CentOS 7已于2024年06月30日停止维护,一些常用的RPM包查找网站也逐渐不再支持对CentOS 7 RPM包的检索,目前还有不少产品依然在使用该版本,那么基于现状,如何便捷的获取、下载想要的RPM包,就成为需要解决的问题。

CentOS Vault镜像如果是离线/隔离网业务,没有内网镜像源提供服务的话,通常是需要进行RPM离线安装的。此前可能会通过以下两个网站下载或查找RPM包:

https://www.rpmfind.net/linux/RPM/index.html

https://pkgs.org

但随着CentOS 7的EOL,上面两个网站也取消了支持。同时国内镜像站上经常用的清华大学开源软件镜像站、中科大开源镜像站都已经发布公告,需要转向CentOS Vault镜像(centos-vault是专门为过期的镜像的保存地址),用于提供已经不受支持的 CentOS(不含 CentOS Stream)的历史归档。

那么基于以上信息,目前还是可以基于清华大学开源软件镜像站、中科大开源镜像站来获取指定的RPM包文件的。

准备环境这里可以准备一台1C1G的虚拟机或者CentOS的docker容器,不管是虚拟机还是容器,操作步骤是一致的。这里我用容器举例,比如目标操作系统是CentOS 7.6.1810,这里先拉取一个镜像:

123456789$ docker pull centos:centos7.6.1810$ docker run -itd centos:centos7.6.1810 bash$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1f7a212da655 centos:centos7.6.1810 "bash" About a minute ago Up About a minute determined_feistel$ docker exec -it 1f7 bash

通过以上几步,我们就具备了一个CentOS 7.6.1810的容器环境。

配置CentOS Vault1、首先打开清华大学开源软件镜像站CentOS Vault的链接:https://mirrors.tuna.tsinghua.edu.cn/help/centos-vault/2、在页面中填入所需要的小版本后按回车,比如我这里是7.6.18103、获取生成好的sed命令:

12345sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810|g" \ -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810|g" \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo

4、拷贝到容器内执行完毕后,可以看到原有的repo已经产生备份,新的repo中已经配置好了baseurl。

123456789101112131415161718192021222324252627282930313233343536373839[root@1f7a212da655 yum.repos.d]# ls -lrttotal 64-rw-r--r-- 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo.bak-rw-r--r-- 1 root root 5701 Nov 23 2018 CentOS-Vault.repo.bak-rw-r--r-- 1 root root 1331 Nov 23 2018 CentOS-Sources.repo.bak-rw-r--r-- 1 root root 630 Nov 23 2018 CentOS-Media.repo.bak-rw-r--r-- 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo.bak-rw-r--r-- 1 root root 1309 Nov 23 2018 CentOS-CR.repo.bak-rw-r--r-- 1 root root 1664 Nov 23 2018 CentOS-Base.repo.bak-rw-r--r-- 1 root root 1724 Jul 3 14:02 CentOS-Base.repo-rw-r--r-- 1 root root 1309 Jul 3 14:02 CentOS-CR.repo-rw-r--r-- 1 root root 649 Jul 3 14:02 CentOS-Debuginfo.repo-rw-r--r-- 1 root root 630 Jul 3 14:02 CentOS-Media.repo-rw-r--r-- 1 root root 1331 Jul 3 14:02 CentOS-Sources.repo-rw-r--r-- 1 root root 5701 Jul 3 14:02 CentOS-Vault.repo-rw-r--r-- 1 root root 329 Jul 3 14:02 CentOS-fasttrack.repo[root@1f7a212da655 yum.repos.d]# [root@1f7a212da655 yum.repos.d]# [root@1f7a212da655 yum.repos.d]# head -n 20 CentOS-Base.repo# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client. You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead.##[base]name=CentOS-$releasever - Base#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infrabaseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#released updates

5、执行yum makecache命令,等到Metadata Cache Created结束即可。

下载离线RPM执行完上述步骤后,可以通过yum的downloadonly机制来获取离线RPM包,如下所示:

123456789101112131415161718192021222324252627282930313233343536$ yum install --downloadonly --downloaddir=./pkg httpd-toolsLoaded plugins: fastestmirror, ovlLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package httpd-tools.x86_64 0:2.4.6-89.el7.centos.1 will be installed--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-tools-2.4.6-89.el7.centos.1.x86_64--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-tools-2.4.6-89.el7.centos.1.x86_64--> Running transaction check---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================================================================================== Package Arch Version Repository Size========================================================================================================================================================================================================Installing: httpd-tools x86_64 2.4.6-89.el7.centos.1 updates 91 kInstalling for dependencies: apr x86_64 1.4.8-3.el7_4.1 base 103 k apr-util x86_64 1.5.2-6.el7 base 92 kTransaction Summary========================================================================================================================================================================================================Install 1 Package (+2 Dependent packages)Total download size: 286 kInstalled size: 584 kBackground downloading packages, then exiting:warning: /root/*/apr-util-1.5.2-6.el7.x86_64.rpm.47.tmp: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY ] 0.0 B/s | 0 B --:--:-- ETA Public key for apr-util-1.5.2-6.el7.x86_64.rpm.47.tmp is not installed(1/3): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00 (2/3): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:00 Public key for httpd-tools-2.4.6-89.el7.centos.1.x86_64.rpm.47.tmp is not installed(3/3): httpd-tools-2.4.6-89.el7.centos.1.x86_64.rpm | 91 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 584 kB/s | 286 kB 00:00:00 exiting because "Download Only" specified

进行pkg目录即可看见下载到本地的RPM包文件:

123456[root@1f7a212da655 pkg]# ls -lrttotal 300-rw-r--r-- 1 root root 94132 Jul 4 2014 apr-util-1.5.2-6.el7.x86_64.rpm-rw-r--r-- 1 root root 105728 Nov 28 2017 apr-1.4.8-3.el7_4.1.x86_64.rpm-rw-r--r-- 1 root root 92776 Jul 31 2019 httpd-tools-2.4.6-89.el7.centos.1.x86_64.rpm[root@1f7a212da655 pkg]#

这里要特别强调的一点,因为容器和虚拟机安装是有明显区别的,所以出现的安装依赖包(Dependent packages)是会比较多的。我这里只是用容器举例,具体是否满足要求、下载的RPM是否都需要安装,需要结合实际情况判断。

替换系统上面说了那么多,其实就是为了应对现有业务或者说存量业务仍在继续使用CentOS 7时获取RPM的方案,还是比较简单和高效的。但落实到最后,还是需要选择替换系统。那么结合个人经验来说,在替换系统的选择上可能需要考虑以下几个方面:1、系统的使用规模、稳定性、安全更新等,比如云厂商的支持力度、系统是否会时不时因为何种组件出现CPU飙升或者挂死、安全更新的频率等2、开发、运维人员的操作习惯,比如对CentOS更为熟悉的团队,可能更适合RHEL系列3、业务上需要适配的操作系统使用哪个系列更多一些,比如支持国产化的操作系统偏RHEL更多还是Debian系列的适配需求更多

就写到这里,最后再说两句😄:1、替换系统的工作是必须要进行的2、开源真好啊

2022超适合CAD使用的显卡清单推荐,快来看看|辭典檢視