#############################

rpm工具:

  •  RPM 全名 RedHat Package Managerment,是由Red Hat公司提出,被众多Linux发行版本所采用,是一种数据库记录的方式来将所需要的软件安装到到Linux系统的一套软件管理机制。
  • 它最大的特点就是将你要安装的软件先编译过,并且打包成为 RPM 机制的文件,通过打包好的软件里面默认的数据库,记录这个软件要安装的时候必须具备的依赖属性软件。
  • 当在你的 Linux 主机安装时,RPM 会先依照软件里面的数据查询Linux 主机的依赖属性软件是否满足,若满足则子以安装,若不满足则不子安装。那么安装的时候就将该软件的信息整个写入 RPM 的数据库中,以便未来的查询、验证与反安装。

linux之 rpm yum dnf_CentOS

 

 

通常,RPM 包采用系统默认的安装路径。安装文件会按照类别分别安装到不同的目录,如下所示:

RPM 包默认安装路径

含 义

/etc/

配置文件安装目录,如/etc/dnf

/usr/bin/

可执行的命令安装目录

/usr/lib/

程序所使用的函数库保存位置

/usr/share/doc/

基本的软件使用手册保存位置

/usr/share/man/

帮助文件(man page文件)保存位置

linux之 rpm yum dnf_ide_02

 


 

 

 

RPM 包还可以手动指定安装路径(不推荐)。

获取指定安装包的安装路径:

  • 先找到rpm安装包:rpm -qa  rpm_pakage_fullname
  • 再根据已经安装的安装包全称获得该安装包的默认安装路径:rpm -ql rpm_pakage_fullname(rpm-ql 只能获取已经用rpm或yum或dnf安装过的软件包的全称,意味着你用源码安装的软件就查不到,另外你没有安装过这个软件包也查不到的)

 

 

[root@igoodful yum.repos.d]rpm -qa *rz*
lrzsz-0.12.20-43.el8.x86_64
[root@igoodful yum.repos.d]rpm -qa lrzsz
lrzsz-0.12.20-43.el8.x86_64
[root@igoodful yum.repos.d]rpm -ql lrzsz-0.12.20-43.el8.x86_64
/usr/bin/rb
/usr/bin/rx
/usr/bin/rz
/usr/bin/sb
/usr/bin/sx
/usr/bin/sz
/usr/lib/.build-id
/usr/lib/.build-id/b2
/usr/lib/.build-id/b2/25f21df8a410853ff0ca69c273bfd6166a36a0
/usr/lib/.build-id/b2/25f21df8a410853ff0ca69c273bfd6166a36a0.1
/usr/lib/.build-id/b2/25f21df8a410853ff0ca69c273bfd6166a36a0.2
/usr/lib/.build-id/f2
/usr/lib/.build-id/f2/29412bed6b8d68690555e59b6910cf19b44a19
/usr/lib/.build-id/f2/29412bed6b8d68690555e59b6910cf19b44a19.1
/usr/lib/.build-id/f2/29412bed6b8d68690555e59b6910cf19b44a19.2
/usr/share/locale/de/LC_MESSAGES/lrzsz.mo
/usr/share/man/man1/rz.1.gz
/usr/share/man/man1/sz.1.gz
[root@igoodful yum.repos.d]rpm -ql lrzsz*
package lrzsz* is not installed
[root@igoodful yum.repos.d]

 

 

 

 

 

 

 

 

 

 

 

官方文档:​​https://dnf.readthedocs.io/en/latest/index.html​

yum和dnf都是管理rmp包的,也只管理rpm包,源码包,它是无法管理的。

CentOS 6和CentOS 7系统中默认使用yum来管理软件包安装,但CentOS  Stream 8开始默认使用DNF来管理软件包安装, Fedora 22 已经默认使用DNF,DNF也是

 

  • dnf缓存文件为:/var/cache/dnf
  • dnf全局配置文为:/etc/dnf/dnf.conf
  • dnf仓库配置文件为:/etc/yum.repos.d/*

 

CentOS 6和CentOS 7系统中安装 DNF:

(1)CentOS 6和CentOS 7系统中为了安装 DNF ,您必须先安装并启用 epel-release 依赖。

 

yum  -y install epel-release

 

(2)然后再使用 epel-release 依赖中的 YUM 命令来安装 DNF 包。在系统中执行以下命令:

 

yum -y install dnf

 

 

 

 搜索rpm软件包:

包含:dnf管理的所有rpm软件包、已经安装过了的rpm安装包,dnf管理的但还没有安装到系统的rpm软件包

 

(1)dnf管理的所有rpm软件包:

dnf list

 

(2)已经安装过了的rpm安装包:

dnf list installed

 

(3)dnf管理的但还没有安装到系统的rpm软件包:

dnf list available

 

(4)根据软件包名称xxx匹配查找rpm软件包:dnf search rpm_name

dnf search xxx

 

(5)根据可执行程序文件名匹配查找rpm软件包:dnf provides exe_name

场景:比如你看见张三执行了某个神秘的命令,然后你也想要安装这个命令来玩,那你就可以找到他执行这个命令的文件位置,然后使用dnf provides  /xxx/yyy/zzz获得rpm安装包名称,然后再去自己的机器上安装即可,但是张三若是源码安装了这个神秘命令,那dnf就无能为力了

dnf provides /bin/bash

 

(6)获取指定rpm软件包的信息:dnf info  rpm_name

[root@igoodful ~]dnf info lrzsz
Last metadata expiration check: 0:03:54 ago on Wed 01 Mar 2023 10:57:18 PM CST.
Available Packages
Name : lrzsz
Version : 0.12.20
Release : 43.el8
Architecture : x86_64
Size : 84 k
Source : lrzsz-0.12.20-43.el8.src.rpm
Repository : baseos
Summary : The lrz and lsz modem communications programs
URL : http://www.ohse.de/uwe/software/lrzsz.html
License : GPLv2+
Description : Lrzsz (consisting of lrz and lsz) is a cosmetically modified
: zmodem/ymodem/xmodem package built from the public-domain version of
: the rzsz package. Lrzsz was created to provide a working GNU
: copylefted Zmodem solution for Linux systems.

[root@igoodful ~]

 

 

 安装软件包:

 (1)直接安装:dnf -y install  rpm_name

[root@igoodful ~]dnf -y install lrzsz
Last metadata expiration check: 0:17:23 ago on Wed 01 Mar 2023 10:57:18 PM CST.
Dependencies resolved.
=======================================================================================================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================================================================================================================================================================================================================================
Installing:
lrzsz x86_64 0.12.20-43.el8 baseos 84 k

Transaction Summary
=======================================================================================================================================================================================================================================================================================================================================
Install 1 Package

Total download size: 84 k
Installed size: 190 k
Downloading Packages:
lrzsz-0.12.20-43.el8.x86_64.rpm 52 kB/s | 84 kB 00:01
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 42 kB/s | 84 kB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : lrzsz-0.12.20-43.el8.x86_64 1/1
Running scriptlet: lrzsz-0.12.20-43.el8.x86_64 1/1
Verifying : lrzsz-0.12.20-43.el8.x86_64 1/1

Installed:
lrzsz-0.12.20-43.el8.x86_64

Complete!
[root@igoodful ~]

 

 

 

 

[root@igoodful ~]dnf provides lrzsz
Last metadata expiration check: 0:19:19 ago on Wed 01 Mar 2023 10:57:18 PM CST.
lrzsz-0.12.20-43.el8.x86_64 : The lrz and lsz modem communications programs
Repo : @System
Matched from:
Provide : lrzsz = 0.12.20-43.el8

lrzsz-0.12.20-43.el8.x86_64 : The lrz and lsz modem communications programs
Repo : baseos
Matched from:
Provide : lrzsz = 0.12.20-43.el8

[root@igoodful ~]

 

 

 

 

 

 

 

 

 dnf history:

  1. 你经常安装centos系统的时候,有一个很大的痛点,那就是每次重新安装系统后,都要重新安装一遍原来的安装包,而且你还不知道安装了哪些安装包,这会让人抓狂;
  2. 这个命令非常有用,通常我们安装系统后,经过一段时间后,你自己也不知道安装了些啥,你可能通过history命令记录,但是这个记录了所有正确与不正确的命令,你也可能包装一下yum或dnf成一个shell脚本来记录自己安装了哪些安装包,但都不如这个命令高效通用;
  3. 这个命令只记录你真正安装了或更新了的安装包,而你执行失败了的安装事不会记录下来的,你多次执行相同的安装命令,也只会记录第一次安装成功的记录,通过这个手段您可以知道在自您使用dnf开始,有什么软件什么时候被安装和卸载;
  4. dnf history是不是都能找到你安装过的所有安装包呢?显然不是的,它只能追踪你用yum或dnf安装过的或更新过的软件包。如果你用源码安装过的软件包,那它就没办法来记录了,这个得你自己记住咯;

 

linux之 rpm yum dnf_安装包_03

 

 

下面就是我本人弄了一个低质量的简单的用于记录安装了哪些包的脚本,也就是包装了dnf命令,但和dnf history比起来还是差远了

[root@igoodful scripts] vim dnff.sh

#!/bin/bash
arg_all="$*"
function dnff(){
if [ ! -d /data/log ];then
mkdir -p /data/log
fi
echo "dnff ${arg_all}" >> /data/log/yum_rpm.log
/usr/bin/dnf ${arg_all}
echo "${arg_all}"
}
function main(){
dnff
}
main

 

 

[root@igoodful root]dnf history 
ID | Command line | Date and time | Action(s) | Altered
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
14 | install dstat | 2023-03-01 21:56 | Install | 7 EE
13 | groupinstall Server | 2023-03-01 21:45 | Install | 7
12 | -y install libcurl-devel | 2023-03-01 16:43 | Install | 1
11 | install libtirpc-devel | 2023-03-01 16:29 | Install | 1
10 | install -y openldap openldap-clients openldap-devel | 2023-03-01 16:27 | Install | 2
9 | -y install pam-devel | 2023-03-01 16:22 | Install | 1
8 | install -y numactl git lrzsz libaio libaio-devel automake autoconf bison libtool ncurses-devel ncurses vim numactl-devel sendmail perl-CPAN perl-Time-HiRes patch cpan perl-DBD-MySQL perl-YAML perl-File-Which perl-DBI bind-utils zlib-devel perl-JSON.noarch openssh-server o | 2023-03-01 16:14 | Install | 20
7 | remove -y java cvs libselinux-devel postgresql mysql ecj jna sinjdoc | 2023-03-01 16:10 | Removed | 17
6 | -y install libevent-devel | 2023-03-01 15:51 | Install | 1
5 | remove cmake | 2023-03-01 14:40 | Removed | 5
4 | -y install make cmake gcc gcc-c++ wget ncurses ncurses-devel openssl openssl-devel libaio libaio-devel bison perl perl-devel | 2023-03-01 14:24 | Install | 86
3 | -y install cmake | 2023-03-01 14:15 | Install | 5
2 | -y install lrzsz | 2023-03-01 13:59 | Install | 1
1 | | 2023-03-01 11:58 | Install | 1633 EE
[root@igoodful root]

 

 

 

 

[root@igoodful root]dnff install dstat
Last metadata expiration check: 0:53:35 ago on Wed 01 Mar 2023 09:02:19 PM CST.
Dependencies resolved.
=======================================================================================================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================================================================================================================================================================================================================================
Installing:
pcp-system-tools x86_64 5.3.7-16.el8 appstream 317 k
Installing dependencies:
libuv x86_64 1:1.41.1-1.el8_4 appstream 156 k
pcp x86_64 5.3.7-16.el8 appstream 1.4 M
pcp-conf x86_64 5.3.7-16.el8 appstream 61 k
pcp-libs x86_64 5.3.7-16.el8 appstream 636 k
pcp-selinux x86_64 5.3.7-16.el8 appstream 63 k
python3-pcp x86_64 5.3.7-16.el8 appstream 178 k

Transaction Summary
=======================================================================================================================================================================================================================================================================================================================================
Install 7 Packages

Total download size: 2.7 M
Installed size: 8.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): pcp-conf-5.3.7-16.el8.x86_64.rpm 70 kB/s | 61 kB 00:00
(2/7): libuv-1.41.1-1.el8_4.x86_64.rpm 86 kB/s | 156 kB 00:01
(3/7): pcp-selinux-5.3.7-16.el8.x86_64.rpm 77 kB/s | 63 kB 00:00
(4/7): pcp-system-tools-5.3.7-16.el8.x86_64.rpm 86 kB/s | 317 kB 00:03
(5/7): pcp-libs-5.3.7-16.el8.x86_64.rpm 90 kB/s | 636 kB 00:07
(6/7): python3-pcp-5.3.7-16.el8.x86_64.rpm 88 kB/s | 178 kB 00:02
(7/7): pcp-5.3.7-16.el8.x86_64.rpm 97 kB/s | 1.4 MB 00:14
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 141 kB/s | 2.7 MB 00:19
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : libuv-1:1.41.1-1.el8_4.x86_64 1/7
Running scriptlet: pcp-selinux-5.3.7-16.el8.x86_64 2/7
Installing : pcp-selinux-5.3.7-16.el8.x86_64 2/7
Running scriptlet: pcp-selinux-5.3.7-16.el8.x86_64 2/7
libsemanage.semanage_direct_install_info: Overriding pcp module at lower priority 100 with module at priority 200.

Installing : pcp-conf-5.3.7-16.el8.x86_64 3/7
Installing : pcp-libs-5.3.7-16.el8.x86_64 4/7
Running scriptlet: pcp-5.3.7-16.el8.x86_64 5/7
Installing : pcp-5.3.7-16.el8.x86_64 5/7
Running scriptlet: pcp-5.3.7-16.el8.x86_64 5/7
Installing : python3-pcp-5.3.7-16.el8.x86_64 6/7
Installing : pcp-system-tools-5.3.7-16.el8.x86_64 7/7
Running scriptlet: pcp-system-tools-5.3.7-16.el8.x86_64 7/7
Verifying : libuv-1:1.41.1-1.el8_4.x86_64 1/7
Verifying : pcp-5.3.7-16.el8.x86_64 2/7
Verifying : pcp-conf-5.3.7-16.el8.x86_64 3/7
Verifying : pcp-libs-5.3.7-16.el8.x86_64 4/7
Verifying : pcp-selinux-5.3.7-16.el8.x86_64 5/7
Verifying : pcp-system-tools-5.3.7-16.el8.x86_64 6/7
Verifying : python3-pcp-5.3.7-16.el8.x86_64 7/7

Installed:
libuv-1:1.41.1-1.el8_4.x86_64 pcp-5.3.7-16.el8.x86_64 pcp-conf-5.3.7-16.el8.x86_64 pcp-libs-5.3.7-16.el8.x86_64 pcp-selinux-5.3.7-16.el8.x86_64 pcp-system-tools-5.3.7-16.el8.x86_64 python3-pcp-5.3.7-16.el8.x86_64

Complete!
install dstat
[root@igoodful root]dnf hist
hist history
[root@igoodful root]dnf hist
hist history
[root@igoodful root]dnf history
ID | Command line | Date and time | Action(s) | Altered
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
14 | install dstat | 2023-03-01 21:56 | Install | 7 EE
13 | groupinstall Server | 2023-03-01 21:45 | Install | 7
12 | -y install libcurl-devel | 2023-03-01 16:43 | Install | 1
11 | install libtirpc-devel | 2023-03-01 16:29 | Install | 1
10 | install -y openldap openldap-clients openldap-devel | 2023-03-01 16:27 | Install | 2
9 | -y install pam-devel | 2023-03-01 16:22 | Install | 1
8 | install -y numactl git lrzsz libaio libaio-devel automake autoconf bison libtool ncurses-devel ncurses vim numactl-devel sendmail perl-CPAN perl-Time-HiRes patch cpan perl-DBD-MySQL perl-YAML perl-File-Which perl-DBI bind-utils zlib-devel perl-JSON.noarch openssh-server o | 2023-03-01 16:14 | Install | 20
7 | remove -y java cvs libselinux-devel postgresql mysql ecj jna sinjdoc | 2023-03-01 16:10 | Removed | 17
6 | -y install libevent-devel | 2023-03-01 15:51 | Install | 1
5 | remove cmake | 2023-03-01 14:40 | Removed | 5
4 | -y install make cmake gcc gcc-c++ wget ncurses ncurses-devel openssl openssl-devel libaio libaio-devel bison perl perl-devel | 2023-03-01 14:24 | Install | 86
3 | -y install cmake | 2023-03-01 14:15 | Install | 5
2 | -y install lrzsz | 2023-03-01 13:59 | Install | 1
1 | | 2023-03-01 11:58 | Install | 1633 EE
[root@igoodful root]