[Linux] rpm && yum (installation and query of software packages)

1. Application programs and system commands

Relationship between applications and system commands

insert image description here

Directory structure of a typical application

insert image description here

linux file

insert image description here

Common Package Packaging Types

insert image description here

Introduction to the Linux Kernel

insert image description here

2.RPM

2.1 rpm package management tool

RPM Package Manager Red-Hat Package Manager

Proposed by Red Hat,Numerous Linux distributionsadopted

CreateUnified Document Database

Detailed logging software packageChanges such as installation, uninstallation, and upgradeinformation

Automatic analysis of package dependencies

RPM package naming principle

insert image description here

insert image description here

insert image description here
insert image description here

2.2 Format of rpm command

The rpm command can achieve almostManagement functions for all RPM packages

Execute the "man rpm" command to get detailed help information about the rpm command

insert image description here

rpm命令功能:

  • query, verifyInformation about rpm packages

  • Install, upgrade, uninstallRPM package

  • Maintain RPM database informationand other comprehensive management operations

2.3. Query rpm package

Query information about installed rpm software

rpm -q [suboption] [software name]

常用选项

-qa、-qi、-ql、-qf、-qc、-qd

查询rpm软件包文件中的信息

rpm -qp [suboption] rpm package file name

常用选项

-qpi、-qpl、-qpc、-qpd

When the "-q" option is used, the ==”/usr/bin/rpmquery”== program is actually called to complete the query work

Package query mainly includes two situations:

(1) In the query systemAlready installedinformation about the package;

(2) querynot yet installedRPM package file information;

For the "-qa "query option, the command parameter (that is, the package name) is not necessary;

For general inquiries, the software nameNo need to specify a version number.

insert image description here

[root@clr ~]# rpm -q rpm  #查询rpm软件包是否已经安装
rpm-4.11.3-45.el7.x86_64
[root@clr ~]# rpm -q yum   #查询yum软件包是否已经安装
yum-3.4.3-168.el7.centos.noarch
[root@clr ~]# systemctl status nfs    #查看nfs服务的状态
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
   
[root@clr ~]# rpm -q nfs-utils   #查询nfs-utils软件包是否已经安装
nfs-utils-1.3.0-0.68.el7.x86_64

rpm -qa command

[root@clr ~]# rpm -qa |wc -l  #统计当前系统中,以rpm方式安装的软件包有多少个
1464
[root@clr ~]# rpm -qa |grep nfs  #统计当前系统中,是否有以rpm方式安装的nfs软件包
libnfsidmap-0.25-19.el7.x86_64
nfs4-acl-tools-0.3.3-21.el7.x86_64
nfs-utils-1.3.0-0.68.el7.x86_64

rpm -qi command

[root@clr ~]# rpm -qi yum  #显示已安装的yum软件包的详细信息
Name        : yum
Version     : 3.4.3
Release     : 168.el7.centos
Architecture: noarch
Install Date: 2023年03月23日 星期四 00时42分15秒
Group       : System Environment/Base
Size        : 5829237
License     : GPLv2+
Signature   : RSA/SHA256, 2020年10月15日 星期四 03时21分12秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : yum-3.4.3-168.el7.centos.src.rpm
Build Date  : 2020年10月02日 星期五 01时03分49秒
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://yum.baseurl.org/
Summary     : RPM package installer/updater/manager
Description :
Yum is a utility that can check for and automatically download and
install updated RPM packages. Dependencies are obtained and downloaded
automatically, prompting the user for permission as necessary.

rpm -ql command

[root@clr ~]# rpm -ql yum  #显示已安装的指定软件yum的文件列表
/etc/logrotate.d/yum
/etc/yum
/etc/yum.conf
/etc/yum.repos.d
/etc/yum/fssnap.d
/etc/yum/pluginconf.d
/etc/yum/protected.d
/etc/yum/vars
/etc/yum/version-groups.conf
/usr/bin/yum
/usr/lib/python2.7/site-packages/rpmUtils
/usr/lib/python2.7/site-packages/rpmUtils/__init__.py

rpm -qc command

[root@clr ~]# rpm -qc yum  	#列出已安装的指定软件yum的配置文件
/etc/logrotate.d/yum
/etc/yum.conf     #yum的配置文件,文件名
/etc/yum/version-groups.conf
[root@clr ~]# rpm -qd yum   #列出已安装的指定软件yum的软件包文档所在位置
/usr/share/doc/yum-3.4.3/AUTHORS
/usr/share/doc/yum-3.4.3/COPYING
/usr/share/doc/yum-3.4.3/ChangeLog
/usr/share/doc/yum-3.4.3/INSTALL
/usr/share/doc/yum-3.4.3/PLUGINS
/usr/share/doc/yum-3.4.3/README
/usr/share/doc/yum-3.4.3/TODO
/usr/share/doc/yum-3.4.3/comps.rng
/usr/share/man/man5/yum.conf.5
/usr/share/man/man8/yum-shell.8
/usr/share/man/man8/yum.8
[root@clr ~]# rpm -qR yum  #列出已安装的指定软件yum依赖的软件包及文件
/usr/bin/python
config(yum) = 3.4.3-168.el7.centos
cpio
diffutils
pygpgme
pyliblzma
python >= 2.4
python(abi) = 2.7
python-iniparse
python-sqlite
python-urlgrabber >= 3.10-8
pyxattr
rpm >= 0:4.11.3-22
rpm-python
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
yum-metadata-parser >= 1.1.0
yum-plugin-fastestmirror
rpmlib(PayloadIsXz) <= 5.2-1

rpm -qf command

[root@clr ~]# rpm -qc yum  #列出已安装的指定软件yum的配置文件
/etc/logrotate.d/yum
/etc/yum.conf
/etc/yum/version-groups.conf

[root@clr ~]# rpm -qf /etc/yum.conf  #查询已安装的指定软件yum,属于哪个安装包(-qf命令参数是文件名或目录名)
yum-3.4.3-168.el7.centos.noarch

[root@clr ~]# rpm -qc httpd  #列出已安装的指定软件httpd的配置文件
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf

[root@clr ~]# rpm -qf /etc/httpd/conf/httpd.conf  #查询已安装的指定软件httpd,属于哪个安装包(-qf命令参数是文件名或目录名)
httpd-2.4.6-95.el7.centos.x86_64

df command

[root@clr /mnt/Packages]# mount /dev/sr0 /mnt^C  #将光盘镜像文件挂载到/dev/sr0/mnt目录下
[root@clr /mnt/Packages]# df  #查看光盘镜像文件的挂载情况
文件系统          1K-块    已用     可用 已用% 挂载点
devtmpfs        1997348       0  1997348    0% /dev
tmpfs           2013076       0  2013076    0% /dev/shm
tmpfs           2013076   12500  2000576    1% /run
tmpfs           2013076       0  2013076    0% /sys/fs/cgroup
/dev/sda1      38817264 5671400 33145864   15% /
tmpfs            402616      12   402604    1% /run/user/42
tmpfs            402616       0   402616    0% /run/user/0
/dev/sr0        4600876 4600876        0  100% /mnt

[root@clr ~]# cd /mnt
[root@clr /mnt]# ls   #Packages目录中包含有所有镜像文件的安装包
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@clr /mnt]# cd Packages/
[root@clr /mnt/Packages]# ls^C   #由于镜像文件安装包过多,会霸屏显示,因此此处省略查看Packages目录中安装包

rpm -qpi command

[root@clr /mnt/Packages]# rpm -qpi zip-3.0-11.el7.x86_64.rpm   #查看指定软件包的详细信息
警告:zip-3.0-11.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
Name        : zip
Version     : 3.0
Release     : 11.el7
Architecture: x86_64
Install Date: (not installed)
Group       : Applications/Archiving
Size        : 815173
License     : BSD
Signature   : RSA/SHA256, 2016年11月21日 星期一 05时04分58秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : zip-3.0-11.el7.src.rpm

rpm -qpl command

[root@clr /mnt/Packages]# rpm -qpl zip-3.0-11.el7.x86_64.rpm   #查询指定软件包的文件列表
警告:zip-3.0-11.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
/usr/bin/zip
/usr/bin/zipcloak
/usr/bin/zipnote
/usr/bin/zipsplit
/usr/share/doc/zip-3.0
/usr/share/doc/zip-3.0/CHANGES
/usr/share/doc/zip-3.0/LICENSE
/usr/share/doc/zip-3.0/README
/usr/share/doc/zip-3.0/README.CR
/usr/share/doc/zip-3.0/TODO
/usr/share/doc/zip-3.0/WHATSNEW
/usr/share/doc/zip-3.0/WHERE
/usr/share/doc/zip-3.0/algorith.txt
/usr/share/man/man1/zip.1.gz

rpm -qpc command

[root@clr /mnt/Packages]# rpm -qpc yum-3.4.3-168.el7.centos.noarch.rpm   #查询指定软件包的配置文件
警告:yum-3.4.3-168.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
/etc/logrotate.d/yum
/etc/yum.conf
/etc/yum/version-groups.conf

rpm -qpd command

[root@clr /mnt/Packages]# rpm -qpd yum-3.4.3-168.el7.centos.noarch.rpm #查询指定软件包帮助文档的位置
警告:yum-3.4.3-168.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
/usr/share/doc/yum-3.4.3/AUTHORS
/usr/share/doc/yum-3.4.3/COPYING
/usr/share/doc/yum-3.4.3/ChangeLog
/usr/share/doc/yum-3.4.3/INSTALL
/usr/share/doc/yum-3.4.3/PLUGINS
/usr/share/doc/yum-3.4.3/README
/usr/share/doc/yum-3.4.3/TODO
/usr/share/doc/yum-3.4.3/comps.rng
/usr/share/man/man5/yum.conf.5
/usr/share/man/man8/yum-shell.8
/usr/share/man/man8/yum.8

insert image description here

2.4 Install, upgrade, uninstall rpm package

Install or upgrade rpm software

rpm [options] rpm package file...

常用选项

-i、-U、-F

卸载指定的rpm软件

rpm -e software name

辅助选项

–force、–nodeps、-h、-v

insert image description here

rpm --nodeps command

insert image description here

rpm -evh command

insert image description here

rpm -Uvh command

[root@clr /mnt/Packages]# rpm -Uvh httpd-2.4.6-95.el7.centos.x86_64.rpm  #升级某个指定软件包,若未安装过,则进行安装。
警告:httpd-2.4.6-95.el7.centos.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
	软件包 httpd-2.4.6-95.el7.centos.x86_64 已经安装  #查询该httpd安装包是否已安装并需要升级,未安装则进行重新安装

rpm -Fvh command

[root@clr /mnt/Packages]# rpm -Fvh httpd-2.4.6-95.el7.centos.x86_64.rpm #升级某个软件包,若未安装过,则放弃安装。
警告:httpd-2.4.6-95.el7.centos.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f

2.5 Maintain database

insert image description here

RPM database: for recording in Linux systemInformation about installing, uninstalling, and upgrading applications, the maintenance is automatically completed by the RPM package management system, generallyNo user intervention required.

When the RPM database is damaged and the Llinux system cannot automatically complete the repair, the rpm command cannot be used to install, uninstall and query the software package normally. At this time, you can use –rebuildbd or –initdbRebuild the rpm database.

In the field of Linux/Unix applications, quite a few software vendors willdigital signature, to ensure that the software'scompleteness, legitimacy. For users. You can use the official public key file provided by the software to automatically verify the downloaded software package. If you install the software,If there is a prompt of verification failure, it means that the software package may have been illegally tampered with

总结: Before the public key file used for digital signature verification is imported, an error will be reported when some RPM software packages in the CD are installed. Need to add to the RPM databaseImport the public key file located in the root directory of the CD

mount /dev/sr0 /mnt/  #挂载光盘镜像文件
rpm --import /mnt/RPM-GPG-KEY-CentOS-7  #导入公钥文件

insert image description here

3.yum

3.1 Configure local yum source warehouse

Yum package manager: It can resolve the dependencies of software packages and realize one-click installation of software packages.

insert image description here

[root@clr /mnt]# cd /etc/yum.repos.d/  #yum软件包安装仓库文件
[root@clr /etc/yum.repos.d]# pwd
/etc/yum.repos.d

配置本地yum源仓库步骤如下所示:

(1) Mount the disc image to the specified location /mnt;

[root@clr ~]# mount /dev/sr0 /mnt
#[root@clr ~]# mount /dev/cdrom /mnt  #与第一句作用相同
[root@clr ~]# df
文件系统          1K-块    已用     可用 已用% 挂载点
devtmpfs        1997348       0  1997348    0% /dev
tmpfs           2013076       0  2013076    0% /dev/shm
tmpfs           2013076   12500  2000576    1% /run
tmpfs           2013076       0  2013076    0% /sys/fs/cgroup
/dev/sda1      38817264 5671740 33145524   15% /
tmpfs            402616      12   402604    1% /run/user/42
/dev/sr0        4600876 4600876        0  100% /mnt
tmpfs            402616       0   402616    0% /run/user/0

(2) Enter the yum warehouse configuration directory, and back up the original *.repo file;

[root@clr /etc/yum.repos.d]# cd /etc/yum.repos.d/
[root@clr /etc/yum.repos.d]# mkdir repo.bak
[root@clr /etc/yum.repos.d]# mv *.repo repo.bak

(3) Create a local yum source configuration file

[root@clr /etc/yum.repos.d]# cd /etc/yum.repos.d/
[root@clr /etc/yum.repos.d]# vim local.repo
[local]
name=local
baseurl file:///mnt
enabled=1
gpgcheck=0

insert image description here

(4) Delete yum cache and update

[root@clr ~]# yum clean all && yum makecache

(5) Test whether the yum source installation is successful

yum install -y ####软件名

insert image description here

3.2 Common operation commands of yum

insert image description here

yum list command

[root@clr ~]# yum list available  #查询系统中已安装的软件包
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile

yum info command

[root@clr /etc/yum.repos.d]# yum info httpd  #查询软件包的描述信息
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :95.el7.centos
大小    :9.4 M
源    :installed
来自源:local
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.

yum search command

[root@clr /etc/yum.repos.d]# yum search all  httpd  #根据某个关键词httpd来查找相关的软件包
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
========================================== 匹配:httpd ===========================================
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
httpd.x86_64 : Apache HTTP Server

yum whatprovides command

[root@clr /etc/yum.repos.d]# yum whatprovides ifconfig      #查询ifconfig命令属于哪个软件包
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
源    :@anaconda
匹配来源:
文件名    :/usr/sbin/ifconfig

3.3 Compile and install software from source code

insert image description here

(1)安装软件依赖包
  yum install -y gcc gcc-c++ make zlib-devel.x86_64 #(用于压缩文件)pcre-devel.x86_64 #(用于正则表达式)

(2)下载,tar解压软件包
   70  cd /opt
   71  rz -E
   72  ls
   73  tar xf nginx-1.22.0.tar.gz 
   74  ls


(3)配置软件模块(安装路径、开启或关闭模块功能、管理服务进程的用户设定)
   86  cd /opt
   87  ls
   88  cd nginx-1.22.0/
   89  ./configure --prefix=/usr/local/nginx
#configure是配置模块的目录,这是更改的安装路径位置/usr/local/nginx

(4)编译,将源码转换为可执行的二进制文件
  90  make (-j2)#默认是单核编译,-j2代表2个cpu编译

(5)安装
  92  make install

insert image description here

Guess you like

Origin blog.csdn.net/cailirong123/article/details/129836370