[other] 【技术分享】RPM包管理
Tofloor
poster avatar
废物头子
deepin
2023-11-02 02:50
Author

软件包管理

  • 软件包管理
    • 一、软件包和RPM
      • (1)RPM软件包介绍
      • (2)RPM使用
        • RPM查询
        • rpm安装与卸载
        • rpm的缺陷
        • 依赖类型以及解决办法
    • 二、dnf管理
      • (1)yum和dnf介绍
      • (2)yum和dnf使用
      • (3)dnf安装和删除各组软件
      • (4)dnf仓库配置
        • 使用网络源
        • 配置本地源
    • 三、搭建本地软件包源

一、软件包和RPM

(1)RPM软件包介绍

RPM包管理器最初是由红帽开发,该程序提供一种标准的方式打包软件进行分发。红帽为红帽企业Linux提供的所有软件包都以RPM软件包的形式提供。

RPM软件包文件名由四个元素组成再加上.rpm后缀:name-version-release.arch

vsftpd-3.0.5-4.el9.x86_64.rpm
name-version-release.arch

name是软件包名字(vsftpd)
version是原始软件包的版本号(3.0.5)
release是基本该版本软件包的发行版本,由软件打包商提供(4.el9)
arch是编译软件包运行的处理器架构(x86_64)。
	noarch表示此软件包内容不限定架构
	x86_84表示64位的x86架构
	aarch64表示64位的ARM架构

当我们从存储库中安装软件包的时候,只需要软件包的名称。如果存在多个版本,则会安装版本号高的软件包,如果一个版本存在多个发行版,则会安装发行版本号更改的软件包。

每个RPM软件包是包含以下三个组成部分:

  • 软件包安装的文件。
  • 与软件包相关的信息,是否要求按照其他软件包,授权许可信息,软件包更新日志等详细信息。
  • 在安装、更新或删除时存在或者运行的脚本。

软件提供商使用GPG密钥对RPM软件包进行数字签名。RPM系统通过确认软件包的GPG密钥签名来验证软件包的完整性。如果GPG签名不匹配,RPM系统拒绝安装软件包。

(2)RPM使用

rpm工具可以用来查看软件信息以及安装和更新软件包。

RPM查询

查询已经安装的软件包
[root@rhce ~]# rpm -qa
libgcc-11.3.1-4.3.el9.x86_64
fonts-filesystem-2.0.5-7.el9.1.noarch
linux-firmware-whence-20230310-133.el9_2.noarch
crypto-policies-20221215-1.git9a18988.el9.noarch
hwdata-0.348-9.7.el9.noarch
xkeyboard-config-2.33-2.el9.noarch
tzdata-2022g-2.el9.noarch
......

查询软件包信息
[root@rhce ~]# rpm -qi  yum 
Name        : yum
Version     : 4.14.0
Release     : 5.el9_2
Architecture: noarch
Install Date: Mon 24 Jul 2023 14:17:47 CST
Group       : Unspecified
Size        : 77898
License     : GPLv2+
Signature   : RSA/SHA256, Thu 16 Mar 2023 19:37:19 CST, Key ID 199e2f91fd431d51
Source RPM  : dnf-4.14.0-5.el9_2.src.rpm
Build Date  : Wed 15 Mar 2023 21:50:32 CST
Build Host  : x86-64-06.build.eng.rdu2.redhat.com
Packager    : Red Hat, Inc. 
Vendor      : Red Hat, Inc.
URL         : https://github.com/rpm-software-management/dnf
Summary     : Package manager
Description :
Utility that allows users to manage packages on their systems.
It supports RPMs, modules and comps groups & environments.

查询软件包安装的文件
[root@rhce ~]# rpm -ql yum
/etc/dnf/protected.d/yum.conf
/etc/yum.conf
/etc/yum/pluginconf.d
/etc/yum/protected.d
/etc/yum/vars
/usr/bin/yum
/usr/share/man/man1/yum-aliases.1.gz
/usr/share/man/man5/yum.conf.5.gz
/usr/share/man/man8/yum-shell.8.gz
/usr/share/man/man8/yum.8.gz

仅查询软件包安装的配置文件
[root@rhce ~]# rpm -qc yum
/etc/dnf/protected.d/yum.conf

仅列出软件包安装的文档文件
[root@rhce ~]# rpm -qd yum
/usr/share/man/man1/yum-aliases.1.gz
/usr/share/man/man5/yum.conf.5.gz
/usr/share/man/man8/yum-shell.8.gz
/usr/share/man/man8/yum.8.gz

查询安装或删除软件包前后运行的脚本
[root@rhce ~]# rpm -q --scripts vsftpd 
postinstall scriptlet (using /bin/sh):

 
if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Initial installation 
    /usr/lib/systemd/systemd-update-helper install-system-units vsftpd.service || : 
fi
preuninstall scriptlet (using /bin/sh):

 
if [ $1 -eq 0 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Package removal, not upgrade 
    /usr/lib/systemd/systemd-update-helper remove-system-units vsftpd.service || : 
fi 


 
if [ $1 -eq 0 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Package removal, not upgrade 
    /usr/lib/systemd/systemd-update-helper remove-system-units vsftpd.target || : 
fi
postuninstall scriptlet (using /bin/sh):

 
if [ $1 -ge 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Package upgrade, not uninstall 
    /usr/lib/systemd/systemd-update-helper mark-restart-system-units vsftpd.service || : 
fi

查询软件包的更新信息
[root@rhce ~]# rpm -q --changelog vsftpd 
* Mon Feb 13 2023 Richard Lescak  - 3.0.5-4
- add patch to replace deprecated Openssl functions 
- Resolves: rhbz#1981411

* Mon Feb 06 2023 Richard Lescak  - 3.0.5-3
- add patch to replace old network functions 
- Resolves: rhbz#1951545

* Fri Nov 11 2022 Richard Lescak  - 3.0.5-2
- reintroduce patch for support of wide-character strings in logs
- Related: rhbz#2018284

* Wed Oct 26 2022 Richard Lescak  - 3.0.5-1
- rebase to version 3.0.5 
- Resolves: rhbz#2018284

* Wed Oct 27 2021 Artem Egorenkov  - 3.0.3-49
- add option to disable TLSv1.3
- Resolves: rhbz#1954682

* Wed Oct 13 2021 Artem Egorenkov  - 3.0.3-48
- ALPACA fix backported from upstram 3.0.5 version
- Resolves: rhbz#1975647

* Tue Aug 10 2021 Mohan Boddu  - 3.0.3-47
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
  Related: rhbz#1991688

* Wed Jun 16 2021 Mohan Boddu  - 3.0.3-46
- Rebuilt for RHEL 9 BETA for openssl 3.0
  Related: rhbz#1971065

* Thu May 20 2021 Artem Egorenkov  - 3.0.3-45
- Temporary pass -Wno-deprecated-declarations to gcc to ignore
  deprecated warnings to be able to build against OpenSSL-3.0
- Resolves: rhbz#1958028

* Fri Apr 16 2021 Artem Egorenkov  - 3.0.3-44
- Enable support for wide-character strings in logs
- Replace unprintables with HEX code, not question marks
- Resolves: rhbz#1948570

* Fri Apr 16 2021 Mohan Boddu  - 3.0.3-43
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937

rpm安装与卸载

使用rpm安装软件包
[root@rhce ~]# rpm -ivh vsftpd-3.0.5-4.el9.x86_64.rpm 
warning: vsftpd-3.0.5-4.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                         ################################# [100%])
Preparing...                         ################################# [100%])
Updating / installing...
   1:vsftpd-3.0.5-4.el9              ################################# [100%])
   
使用rpm卸载软件包
[root@rhce ~]# rpm -e vsftpd 

常见选项
-i		安装
-v		显示详细信息
-h		显示进度条
-e		移除软件包
--replacepkgs	重新安装。相当于--force
--oldpackage	安装旧版的软件包
--replacefiles	忽略冲突
--nodeps		忽略依赖性关系

rpm的缺陷

以使用rpm安装samba来看,在下面的安装过程中,可以发现软件包直接存在依赖关系,rpm无法自动处理这里依赖关系,需要我们根据依赖关系先后去安装软件包。

[root@rhce Packages]# rpm -ivh samba-4.17.5-102.el9.x86_64.rpm 
warning: samba-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
	libREG-FULL-samba4.so()(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	libREG-FULL-samba4.so(SAMBA_4.17.5_SAMBA4)(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	libRPC-SERVER-LOOP-samba4.so()(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	libRPC-SERVER-LOOP-samba4.so(SAMBA_4.17.5_SAMBA4)(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	libnetapi = 0:4.17.5-102.el9 is needed by samba-0:4.17.5-102.el9.x86_64
	libxattr-tdb-samba4.so()(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	libxattr-tdb-samba4.so(SAMBA_4.17.5_SAMBA4)(64bit) is needed by samba-0:4.17.5-102.el9.x86_64
	samba-common-tools = 0:4.17.5-102.el9 is needed by samba-0:4.17.5-102.el9.x86_64
	samba-dcerpc = 0:4.17.5-102.el9 is needed by samba-0:4.17.5-102.el9.x86_64
	samba-libs = 0:4.17.5-102.el9 is needed by samba-0:4.17.5-102.el9.x86_64
//安装samba发现缺少依赖包,需要安装依赖包
[root@rhce Packages]# rpm -ivh samba-libs-4.17.5-102.el9.x86_64.rpm 
warning: samba-libs-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-libs-0:4.17.5-102.el9      ################################# [100%]
[root@rhce Packages]# rpm -ivh samba-dcerpc-4.17.5-102.el9.x86_64.rpm 
warning: samba-dcerpc-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
	libnetapi = 0:4.17.5-102.el9 is needed by samba-dcerpc-0:4.17.5-102.el9.x86_64
	libnetapi.so.1()(64bit) is needed by samba-dcerpc-0:4.17.5-102.el9.x86_64
	libnetapi.so.1(NETAPI_1.0.0)(64bit) is needed by samba-dcerpc-0:4.17.5-102.el9.x86_64
//安装samba-dcerpc发现缺少依赖包,需要先安装依赖包。
[root@rhce Packages]# rpm -ivh libnetapi-4.17.5-102.el9.x86_64.rpm 
warning: libnetapi-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:libnetapi-0:4.17.5-102.el9       ################################# [100%]
[root@rhce Packages]# rpm -ivh samba-dcerpc-4.17.5-102.el9.x86_64.rpm 
warning: samba-dcerpc-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-dcerpc-0:4.17.5-102.el9    ################################# [100%]
[root@rhce Packages]# rpm -ivh samba-common-tools-4.17.5-102.el9.x86_64.rpm 
warning: samba-common-tools-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
	samba-ldb-ldap-modules = 0:4.17.5-102.el9 is needed by samba-common-tools-0:4.17.5-102.el9.x86_64
[root@rhce Packages]# rpm -ivh samba-ldb-ldap-modules-4.17.5-102.el9.x86_64.rpm 
warning: samba-ldb-ldap-modules-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-ldb-ldap-modules-0:4.17.5-1################################# [100%]
[root@rhce Packages]# rpm -ivh samba-common-tools-4.17.5-102.el9.x86_64.rpm 
warning: samba-common-tools-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-common-tools-0:4.17.5-102.e################################# [100%]
[root@rhce Packages]# rpm -ivh samba-4.17.5-102.el9.x86_64.rpm 
warning: samba-4.17.5-102.el9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-0:4.17.5-102.el9           ################################# [100%]

依赖类型以及解决办法

  • 树形依赖:a-b-c,要安装a,必选先安装b,而按照b需要先安装c。解决此依赖的办法就是从后往前安装,即先安装c,再安装b,最后安装a。
  • 环形依赖:a-b-c-a,各个安装包之间的依赖关系构成环状。解决此类型依赖是用一条命令同时安装所有的软件包。

二、dnf管理

使用rpm命令安装软件包不能自动解决依赖关系。为了解决这个问题,在基于RPM包管理上出现了新的软件包管理器。

RHEL8之前使用YUM进行软件包管理,RHEL8之后由YUM变成了DNF进行软件包管理。yum和dnf在命令上没有太大区别,从RHEL8开始已经逐渐开始转向DNF,但是yum也同意可以使用。

(1)yum和dnf介绍

  • YUM(全称为 Yellow dog Updater, Modified)是基于RPM包管理,能够从指定的YUM源服务器自动下载RPM包进行安装和更新,可以自动处理依赖性关系,并且一次安装所有依赖软件包。
  • DNF(全称为Dandified yum)是新一代的rpm软件包管理器,克服了YUM包管理器的一些瓶颈,提升了包括用户体验,内存占用,依赖分析,运行速度等多方面的内容。其余方面跟YUM差别不大。

(2)yum和dnf使用

yum listdnf list):查看已经安装和可用的软件包


通过上面命令显示,可以发现yum和dnf的显示结果没有不同,下午中所有命令演示仅使用dnf。

dnf search KEYWORD:根据仅在名称和摘要字段中找到关键字列出软件包。


dnf info PACKAGENAME:查看软件包的详细信息。


dnf provides PATHNAME:显示与指定的路径名匹配的软件包


dnf install -y PACKAGENAME:获取并安装软件包,包括所有依赖项。


dnf update -y PACKAGENAME:获取指定软件包的较新版本,包括所有的依赖项。该操作通常会保留当前配置文件。但是在某些情况下,如果软件提供商认为旧文件不可用,则会对配置文件重命令。如果不指定包名,将会更新所有。


dnf remove -y PACKAGENAME:移除指定软件包,包括所有受支持的软件包。

[root@rhce ~]# dnf remove -y httpd
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.

Dependencies resolved.
=====================================================================================================================
 Package                         Architecture        Version                           Repository               Size
=====================================================================================================================
Removing:
 httpd                           x86_64              2.4.53-11.el9_2.4                 @AppStream               59 k
Removing unused dependencies:
 apr                             x86_64              1.7.0-11.el9                      @AppStream              289 k
 apr-util                        x86_64              1.6.1-20.el9                      @AppStream              213 k
 apr-util-bdb                    x86_64              1.6.1-20.el9                      @AppStream               16 k
 apr-util-openssl                x86_64              1.6.1-20.el9                      @AppStream               24 k
 httpd-core                      x86_64              2.4.53-11.el9_2.4                 @AppStream              4.6 M
 httpd-filesystem                noarch              2.4.53-11.el9_2.4                 @AppStream              400  
 httpd-tools                     x86_64              2.4.53-11.el9_2.4                 @AppStream              198 k
 mod_http2                       x86_64              1.15.19-4.el9_2.4                 @AppStream              385 k
 mod_lua                         x86_64              2.4.53-11.el9_2.4                 @AppStream              142 k
 redhat-logos-httpd              noarch              90.4-1.el9                        @AppStream               12 k

Transaction Summary
=====================================================================================================================
Remove  11 Packages

Freed space: 5.9 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                             1/1 
  Running scriptlet: httpd-2.4.53-11.el9_2.4.x86_64                                                             1/11 
  Erasing          : httpd-2.4.53-11.el9_2.4.x86_64                                                             1/11 
  Running scriptlet: httpd-2.4.53-11.el9_2.4.x86_64                                                             1/11 
  Erasing          : mod_lua-2.4.53-11.el9_2.4.x86_64                                                           2/11 
  Erasing          : mod_http2-1.15.19-4.el9_2.4.x86_64                                                         3/11 
  Erasing          : redhat-logos-httpd-90.4-1.el9.noarch                                                       4/11 
  Erasing          : httpd-core-2.4.53-11.el9_2.4.x86_64                                                        5/11 
  Erasing          : httpd-tools-2.4.53-11.el9_2.4.x86_64                                                       6/11 
  Erasing          : httpd-filesystem-2.4.53-11.el9_2.4.noarch                                                  7/11 
  Erasing          : apr-util-1.6.1-20.el9.x86_64                                                               8/11 
  Erasing          : apr-util-bdb-1.6.1-20.el9.x86_64                                                           9/11 
  Erasing          : apr-1.7.0-11.el9.x86_64                                                                   10/11 
  Erasing          : apr-util-openssl-1.6.1-20.el9.x86_64                                                      11/11 
  Running scriptlet: apr-util-openssl-1.6.1-20.el9.x86_64                                                      11/11 
  Verifying        : apr-1.7.0-11.el9.x86_64                                                                    1/11 
  Verifying        : apr-util-1.6.1-20.el9.x86_64                                                               2/11 
  Verifying        : apr-util-bdb-1.6.1-20.el9.x86_64                                                           3/11 
  Verifying        : apr-util-openssl-1.6.1-20.el9.x86_64                                                       4/11 
  Verifying        : httpd-2.4.53-11.el9_2.4.x86_64                                                             5/11 
  Verifying        : httpd-core-2.4.53-11.el9_2.4.x86_64                                                        6/11 
  Verifying        : httpd-filesystem-2.4.53-11.el9_2.4.noarch                                                  7/11 
  Verifying        : httpd-tools-2.4.53-11.el9_2.4.x86_64                                                       8/11 
  Verifying        : mod_http2-1.15.19-4.el9_2.4.x86_64                                                         9/11 
  Verifying        : mod_lua-2.4.53-11.el9_2.4.x86_64                                                          10/11 
  Verifying        : redhat-logos-httpd-90.4-1.el9.noarch                                                      11/11 
Installed products updated.

Removed:
  apr-1.7.0-11.el9.x86_64                   apr-util-1.6.1-20.el9.x86_64         apr-util-bdb-1.6.1-20.el9.x86_64   
  apr-util-openssl-1.6.1-20.el9.x86_64      httpd-2.4.53-11.el9_2.4.x86_64       httpd-core-2.4.53-11.el9_2.4.x86_64
  httpd-filesystem-2.4.53-11.el9_2.4.noarch httpd-tools-2.4.53-11.el9_2.4.x86_64 mod_http2-1.15.19-4.el9_2.4.x86_64 
  mod_lua-2.4.53-11.el9_2.4.x86_64          redhat-logos-httpd-90.4-1.el9.noarch

Complete!

(3)dnf安装和删除各组软件

dnf也具有组的概念,即针对特定特定目的而一起安装的相关软件集合。一个组提供的软件包或在组里面有mandatory(必要安装的软件包)、default(默认会安装的软件包)或optional(可以不安装的软件包)。

命令 作用
dnf grouplist 显示已经安装和可用的组名称
dnf gorupinfo 显示组的相关信息
dnf groupinstall 安装
dnf groupremove 移除
dnf groupupdate 更新

(4)dnf仓库配置

不论是dnf还是yum来安装软件包的时候,都需要依靠软件包仓库来完成,红帽在默认情况下是没有配置任何软件包的仓库,除非将系统注册到订阅管理服务。所有在红帽中当我们没有订阅的时候,需要我们手动配置软件包仓库以便来使用dnf工具。

在系统关于仓库源的配置存放在 /etc/yum.repos.d/目录下,文件必选以 .repo结尾.

使用网络源

当我们设备可用连接到互联网的时候,我们可用去使用一些网络源,如红帽官方的软件源或者国内的阿里源,清华源等源仓库。下面以添加阿里源中docekr源仓库为例。

使用wget命令
[root@rhce ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
--2023-08-15 11:07:47--  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 36.158.203.214, 36.158.203.218, 36.158.203.219, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|36.158.203.214|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2081 (2.0K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’

/etc/yum.repos.d/docker-ce.repo                      100%[======================================================================================================================>]   2.03K  --.-KB/s    in 0s    

2023-08-15 11:07:47 (16.1 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved [2081/2081]

使用yum-config-manager命令
[root@rhce ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
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.

Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

注:在某些情况下可能系统没有安装wget和yum-config-manager命令,这两个命令分别来自wget包和yum-utils包,
如果系统中没有这两个命令,就先安装这两个包。
配置本地源

上述方式是我们在可以连接到互联网的时候,可以使用网络源,当我们的系统没有连接到互联网中,或者生产环境不允许连接互联网。那么我们就需要配置本地源仓库,来保证dnf的使用。下面分别介绍RHEL7和RHEL9的本地源配置

RHEL7
第一步:将镜像挂载到本地,每一个镜像文件都包含了一定数量的软件包,我们本地软件包仓库就是依赖于镜像文件中的软件包。
[root@localhost ~]# mkdir /cdrow				#创建一个目录,用于挂载镜像
[root@localhost ~]# mount /dev/sr0 /cdrow/
mount: /dev/sr0 写保护,将以只读方式挂载

第二步;编写配置文件,以使用软件包仓库。
[root@localhost ~]# vim /etc/yum.repos.d/local.repo
[local]							#本地源仓库的名称
name=local						#仓库描述,可不写
baseurl=file:///cdrow			#仓库路径,必写。file://表示使用的协议,本地文件使用file://;如果是网络源使用http://
enabled=1						#是否启用仓库,1表示启用,0表示不启用。
gpgcheck=0						#是否校验GPG密钥,1表示启用,0表示不启用。

如果将gpgcheck设置为1,则需要添加以下配置
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

第三步:检查仓库是否可用。当状态为可用并且可以看到软件包数量,即表示仓库可以正常用了。
[root@localhost ~]# yum clean all
[root@localhost ~]# yum repolist all
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

local                                                                                                                                                                 | 2.8 kB  00:00:00   
(1/2): local/group                                                                                                                                                    | 628 kB  00:00:00   
(2/2): local/primary                                                                                                                                                  | 2.1 MB  00:00:00   
local                                                                                                                                                                              5230/5230
源标识                                                                                   源名称                                                                                   状态
local                                                                                    local                                                                                    启用: 5,230
repolist: 5,230


RHEL9
[root@rhce ~]# mkdir /cdrow
[root@rhce ~]# mount /dev/sr0 /cdrow/
mount: /cdrow: WARNING: source write-protected, mounted read-only.
[root@rhce ~]# vim /etc/yum.repos.d/local.repo 
[AppStream]
baseurl=file:///cdrow/AppStream
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[BaseOS]
baseurl=file:///cdrow/BaseOS
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@rhce ~]# dnf clean all
[root@rhce ~]# dnf repolist all
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.

Repository 'AppStream' is missing name in configuration, using id.
Repository 'BaseOS' is missing name in configuration, using id.
repo id                                                                                               repo name                                                                                              status
AppStream                                                                                             AppStream                                                                                              enabled
BaseOS                                                                                                BaseOS                                                                                                 enabled

为什么本文中会使用RHEL7和RHEL9为例。各位在完成上面配置之后可以发现,在RHEL7中baseurl指定的路径就是我们光盘挂载的目录,而RHEL9在挂载目录的基础之上后面还有AppStream目录和BaseOS目录。这是因为在RHEL8开始,镜像文件中将软件包分别放在两个目录当中。在镜像文件中我们的软件包都保存在一个名为 Packages的目录中。

RHEL7
[root@localhost Packages]# pwd
/cdrow/Packages
RHEL9
[root@rhce Packages]# pwd
/cdrow/AppStream/Packages
[root@rhce Packages]# pwd
/cdrow/BaseOS/Packages

那么我们是依据Packages目录来决定路径的吗?实际上我们并不是根据此路径来决定的,在镜像文件中还存在一个很重要的目录repodata。回到之前提到的,为什么dnf可用自动解决依赖问题。dnf就是依据repodate目录中的内容来解决软件包之间的依赖问题,所以我们的路径是依据repodate所在目录来决定我们配置文件中的路径。

三、搭建本地软件包源

在上面配置软件源仓库中提到,不论在什么情况下,都可以有软件源仓库使用。但是在镜像文件中的软件包数量是比较少的,且部分软件在软件包中是没有的,如MySQL,docker,kubernetes,nginx等。所以在内网情况下,我们可能所以搭建一个自己内网仓库,来给内网中设备提供网络源。以centos7中配置内网仓库为例

需求:配置一个内网仓库,要求包含centos7全部的网络源,阿里云的dokcer源以及kubernetes源。
第一步:同步所需的源仓库
#下载创建仓库的工具
[root@lb ~]# yum -y install yum-utils createrepo
#拉取阿里云的docker源和kubernetes源
[root@lb ~]# cat <

如果需要在一个内网的环境中部署软件仓库,大部分情况下会找厂商购买内网仓库。如果没有,可以在进入内网之前,安装上述步骤搭建好内网仓库,将整个目录压缩打包,可以直接拷贝到内网使用。

Reply Favorite View the author
All Replies
晚秋(lateautumn)
Moderator
2023-11-02 18:45
#1

rpm包与咱深度系统,没有什么关联吧?我曾用过中兴新支点操作系统1个月,就属于rpm包,软件生态不如deb

Reply View the author
jjcui8595
deepin
2023-11-02 18:55
#2

感谢分享知识。但deepin使用deb包,楼主可以重点介绍一下dpkg apt等知识

Reply View the author
废物头子
deepin
2023-11-02 19:04
#3
晚秋(lateautumn)

rpm包与咱深度系统,没有什么关联吧?我曾用过中兴新支点操作系统1个月,就属于rpm包,软件生态不如deb

我主要用的都是rpm,深度有直接软件商店,我后续应该会写一份deb的包管理工具

Reply View the author
晚秋(lateautumn)
Moderator
2023-11-02 19:10
#4
废物头子

我主要用的都是rpm,深度有直接软件商店,我后续应该会写一份deb的包管理工具

中兴新支点也有软件商店,但很少有人用,现在感觉基本上不维护更新了。还好我撤退的很及时。joy

Reply View the author
花雨落逝
deepin
2023-11-02 21:22
#5
晚秋(lateautumn)

中兴新支点也有软件商店,但很少有人用,现在感觉基本上不维护更新了。还好我撤退的很及时。joy

他们家那系统我用不了,硬件不适配

Reply View the author
兆兆嘟嘟嘟
deepin
2023-11-02 21:33
#6
废物头子

我主要用的都是rpm,深度有直接软件商店,我后续应该会写一份deb的包管理工具

你主要用哪个发行版?

Reply View the author
废物头子
deepin
2023-11-02 22:21
#7
兆兆嘟嘟嘟

你主要用哪个发行版?

rhle,centos,uos-server,龙蜥,欧拉

Reply View the author
BLumia
deepin
2023-11-03 01:46
#8

如果是 rpm 系发行版用户的话,有兴趣的话可以考虑加入 dde-port SIG 小组,一起参与 openSUSE 或者 Fedora 的 DDE 移植 :)

Reply View the author
兆兆嘟嘟嘟
deepin
2023-11-03 05:27
#9
废物头子

rhle,centos,uos-server,龙蜥,欧拉

后几个我都知道,只有RHEL我没找到地方下载。

另外,我还知道中国的两个:中兴新支点、中国移动BCLinux。

Reply View the author