RPM包概述
什么是rpm包
- 由红帽开发的软件 升级、安装、卸载、查询 工具
为什么要使用rpm
- 就像在windows系统中一样,如果你想要安装一个QQ,安装一个微信,安装一款游戏,首先要去该软件的官网上去下载相关的软件包,通常都是.exe的安装包。还有那种绿色软件包,一下载下来,解压开就能使用无需安装。
- 那么Linux中也有很多种类的安装包,我们再Linux上也需要安装软件,软件包的种类也有很多,但是最方便,最简单,最容易,速度最快的,就是rpm包。
rpm包命名规则
## tree-1.60-10.el7.x86_64.rpm
tree:软件名称
1.6.0:版本号
10:该版本的发布次数
el7:适用系统版本(RedHat7,CentOS7)向下兼容
x86_64:系统平台 64 x86:32位 i386
rpm:包后缀名
Linux中软件的安装方式
rpm安装:已经编译好的源码包,下再下来后,直接使用rpm命令安装即可 #缺点:版本会低于官方版本
源码安装:先编译,将源代码翻译成系统认识的软件,再安装 #缺点:步骤复杂繁琐
二进制安装:绿色软件(免安装) #缺点:不是所有程序都有二进制包
RPM包获取途径
- 系统光盘镜像/CentOS官网:TP
1.检查光盘是否放入光驱
mount语法:源设备文件 目标路径
[root@Y ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
# 查看磁盘信息
[root@Y ~]# df -h (查看磁盘分区情况,磁盘使用情况,也能查看到挂载设备及目录)
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/nvme0n1p3 19G 1.8G 17G 10% /
/dev/nvme0n1p1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /mnt
# 卸载语法
umount 目标路径
# 例如:umount /mnt
## 挂载报错:
[root@ Y ~ ] # mount /dev/cdrom /
mount: no medium found on /dev/sr0
原因:设备文件是空的,里面没有任何内容,光驱没有连接
## 卸载报错
[root@Y mnt]# umount /mnt (不能再自身目录下卸载)
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@Y mnt]# cd
[root@Y ~]# umount /mnt
原因:设备繁忙
## 查看挂载结果
[root@Y ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@Y ~]# ll /mnt/
total 696
-rw-r--r--. 3 root root 14 Oct 30 2020 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Oct 27 2020 EFI
-rw-rw-r--. 21 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 21 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Oct 27 2020 images
drwxr-xr-x. 2 root root 2048 Nov 3 2020 isolinux
drwxr-xr-x. 2 root root 2048 Oct 27 2020 LiveOS
drwxr-xr-x. 2 root root 673792 Nov 4 2020 Packages
drwxr-xr-x. 2 root root 4096 Nov 4 2020 repodata
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Nov 4 2020 TRANS.TBL
[root@Y Packages]# cd /mnt/Packages/
[root@Y Packages]# ll /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
-rw-rw-r--. 3 root root 47508 Jul 4 2014 /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
- RPM包查询官方网站:TP
- 其他软件官方网站
rpm命令使用-安装
# 语法:
rpm [选项] rpm包名
rpm包名:
-本地包名:在系统中某个目录下的rpm包
-远程包名:不用下载,直接使用网站上的rpm包
# 选项:
-i:安装
-v:显示安装的过程
-h:显示安装的进度条
--test:仅测试,不安装
--force:强制安装
--nodeps:忽略依赖关系
# 举例 -i
[root@Y ~]# yum remove tree -y (卸载tree)
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Removing:
tree x86_64 1.6.0-10.el7 @base 87 k
Transaction Summary
=============================================================================================
Remove 1 Package
Installed size: 87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Removed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@Y ~]# rpm -i /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm (使用rpm命令 安装)
[root@Y ~]# tree(可以使用)
.
└── create
0 directories, 1 file
# 举例 -v
[root@Y ~]# rpm -iv /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing packages...
tree-1.6.0-10.el7.x86_64
(安装过程)
# 举例 -h
[root@Y ~]# rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tree-1.6.0-10.el7 ################################# [100%]
(显示安装进度条)
# 举例 --test
[root@Y ~]# rpm -ivh --test /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing... ################################# [100%]
(测试成功可以安装,但不安装,几乎没什么用)
# 举例 --force --nodeps
[root@Y ~]# rpm -ivh --force --nodeps samba-4.8.3-4.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:samba-0:4.8.3-4.el7 ################################# [100%]
(并没有解决依赖问题,只是跳过依赖包安装了,所以安装的会有缺点)
## 注意:rpm命令管理rpm包的缺点,无法解决依赖关系
https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/Packages/zip-3.0-11.el7.x86_64.rpm
(阿里云的安装包)
rpm命令使用-查询
# 语法:
rpm [选项] rpm包名
# 选项
-q:查看指定的安装包是否安装
--- 以下选项皆要配合-q使用 ---
-a:全部安装过的包
-i:详细信息
-l:列出rpm包相关的配置文件和目录
-c:只查看该软件包相关的配置文件
-d:只查看该软件的帮助文档文件
-f:反向查找,根据配置文件,目录,帮助文档,查找该文件属于哪个包
--scripts:查看安装包,安装之前之后,和卸载之前之后要执行的脚本
---------- 和上面选项配合使用 --------------
-p:查询未安装的包相关信息
-qip:查看没有安装包的详细信息(指定一个已存在的完整包名或者远程包名)
-qlp:查看没有安装包会生成那些文件(指定一个已存在的完整包名或者远程包名)
-qcp:查看没有安装包会生成哪些配置文件(指定一个已存在的完整包名或者远程包名)
-qdp:查看没有安装包会生成哪些帮助文件(指定一个已存在的完整包名或者远程包名)
# 举例 -q
[root@Y ~]# rpm -q tree
package tree is not installed
(这是没有安装)
[root@Y ~]# rpm -q sudo
sudo-1.8.23-10.el7.x86_64
[root@Y ~]# rpm -q gzip
gzip-1.5-10.el7.x86_64
[root@Y ~]# rpm -q tree
tree-1.6.0-10.el7.x86_64
# 举例 -q -a
[root@Y ~]# rpm -qa
[root@Y ~]# rpm -qa |grep 'cp'
`cp`io-2.11-28.el7.x86_64
t`cp`_wrappers-libs-7.6-77.el7.x86_64
dh`cp`-libs-4.2.5-82.el7.centos.x86_64
pro`cp`s-ng-3.3.10-28.el7.x86_64
dh`cp`-common-4.2.5-82.el7.centos.x86_64
[root@Y ~]# rpm -qa |grep 'net'
libnf`net`link-1.0.1-4.el7.x86_64
lib`net`filter_conntrack-1.0.6-1.el7_3.x86_64
`net`-tools-2.0-0.25.20131004git.el7.x86_64
dracut-`net`work-033-572.el7.x86_64
#以上``都是自己加,虚拟机上显示的为过滤内容
# 举例 -q -i 命令组合使用
[root@Y ~]# rpm -qi `rpm -qa|grep 'net'`
[root@Y ~]# rpm -qi $(rpm -qa|grep 'net')
[root@Y ~]# rpm -qa|grep 'net'|xargs rpm -qi
Name : libnfnetlink
Version : 1.0.1
Release : 4.el7
Architecture: x86_64
Install Date: Wed 16 Mar 2022 12:21:19 AM CST
Group : System Environment/Libraries
Size : 47123
License : GPLv2+
Signature : RSA/SHA256, Fri 04 Jul 2014 11:01:58 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : libnfnetlink-1.0.1-4.el7.src.rpm
Build Date : Tue 10 Jun 2014 08:21:22 AM CST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://netfilter.org
Summary : Netfilter netlink userspace library
Description :
libnfnetlink is a userspace library that provides some low-level
nfnetlink handling functions. It is used as a foundation for other, netfilter
subsystem specific libraries such as libnfnetlink_conntrack, libnfnetlink_log
and libnfnetlink_queue.
----------------------------
Name : libnetfilter_conntrack
Version : 1.0.6
Release : 1.el7_3
Architecture: x86_64
Install Date: Wed 16 Mar 2022 12:21:19 AM CST
Group : System Environment/Libraries
Size : 143566
License : GPLv2+
Signature : RSA/SHA256, Fri 26 May 2017 07:23:10 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : libnetfilter_conntrack-1.0.6-1.el7_3.src.rpm
Build Date : Fri 26 May 2017 03:59:45 AM CST
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://netfilter.org
Summary : Netfilter conntrack userspace library
Description :
libnetfilter_conntrack is a userspace library providing a programming
interface (API) to the in-kernel connection tracking state table.
---------------------------------
Name : net-tools
Version : 2.0
Release : 0.25.20131004git.el7
Architecture: x86_64
Install Date: Thu 14 Apr 2022 07:34:34 PM CST
Group : System Environment/Base
Size : 938978
License : GPLv2+
Signature : RSA/SHA256, Fri 23 Aug 2019 05:36:04 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : net-tools-2.0-0.25.20131004git.el7.src.rpm
Build Date : Fri 09 Aug 2019 09:10:26 AM CST
Build Host : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://sourceforge.net/projects/net-tools/
Summary : Basic networking tools
Description :
The net-tools package contains basic networking tools,
including ifconfig, netstat, route, and others.
Most of them are obsolete. For replacement check iproute package.
------------------------
Name : dracut-network
Version : 033
Release : 572.el7
Architecture: x86_64
Install Date: Wed 16 Mar 2022 12:21:37 AM CST
Group : System Environment/Base
Size : 149776
License : GPLv2+ and LGPLv2+
Signature : RSA/SHA256, Thu 15 Oct 2020 02:48:11 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : dracut-033-572.el7.src.rpm
Build Date : Wed 30 Sep 2020 11:57:59 PM CST
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : https://dracut.wiki.kernel.org/
Summary : dracut modules to build a dracut initramfs with network support
Description :
This package requires everything which is needed to build a generic
all purpose initramfs with network support with dracut.
#(先查看所有安装过包,然后过滤出带`net`的包,然后查看过滤后的包的详细信息)
# 举例 -q -l
[root@Y ~]# rpm -ql zip
/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
/usr/share/man/man1/zipcloak.1.gz
/usr/share/man/man1/zipnote.1.gz
/usr/share/man/man1/zipsplit.1.gz
# 举例 -q -c
[root@Y ~]# rpm -qc mariadb
/etc/my.cnf.d/client.cnf
# 举例 -q -d
[root@Y ~]# rpm -qd zip (都是帮助文档,ql其实就能看)
/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
/usr/share/man/man1/zipcloak.1.gz
/usr/share/man/man1/zipnote.1.gz
/usr/share/man/man1/zipsplit.1.gz
# 举例 -q -f
[root@Y ~]# rpm -qf /etc/hostname
systemd-219-78.el7.x86_64
(hostname属于上面的包)
[root@Y ~]# rpm -qf /etc/passwd
setup-2.8.71-11.el7.noarch
rpm命令使用-升级
# 选项
-U:update升级,如果老版本不存在,则安装,如果老版本存在则升级
-f:必须有老版本存在
## 查询当前系统中安装nginx的包(1.10版本)
[root@Y ~]# rpm -qa|grep nginx
nginx-1.10.0-1.el7.ngx.x86_64
## 使用ivh安装nginx 1.12版本的包
[root@Y ~]# rpm -ivh nginx-1.12.0-1.el7.ngx.x86_64.rpm
# 报错如下:因为系统中已存在1.10版本的nginx所以无法使用ivh安装
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62:
NOKEY
Preparing... ################################# [100%]
file /etc/logrotate.d/nginx from install of nginx-1:1.12.0-1.el7.ngx.x86_64
conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/sbin/nginx from install of nginx-1:1.12.0-1.el7.ngx.x86_64
conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/sbin/nginx-debug from install of nginx-1:1.12.0-1.el7.ngx.x86_64conflicts
with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/lib/systemd/system/nginx.service from install of nginx-1:1.12.0- 1.el7.
ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7.ngx.x86_64
file /usr/libexec/initscripts/legacy-actions/nginx/upgrade from install of
nginx- 1:1.12.0-1.el7.ngx.x86_64 conflicts with file from package nginx-1:1.10.0-1.el7
.ngx.x86_
## 使用Uvh安装,会将已存在的老版本卸载,升级成新1.12版本
[root@Y ~]# rpm -Uvh nginx-1.12.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.12.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62:
NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:nginx-1:1.12.0-1.el7.ngx ################################# [ 50%]
Cleaning up / removing...
2:nginx-1:1.10.0-1.el7.ngx ################################# [100%]
## 查看当前系统中的nginx版本为升级后的1.12版本
[root@Y ~]# rpm -qa|grep nginx
nginx-1.12.0-1.el7.ngx.x86_64
rpm命令使用-卸载
# 选项
-e:后面接卸载的包名即可
[root@Y ~]# rpm -qa|grep nginx
nginx-1.12.0-1.el7.ngx.x86_64
[root@Y ~]# rpm -e nginx
[root@Y ~]# rpm -qa|grep nginx
[root@Y ~]# rpm -qa|grep mariadb
mariadb-5.5.68-1.el7.x86_64
mariadb-server-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64
[root@Y ~]# rpm -e $(rpm -qa|grep mariadb)
镜像站地址
1.阿里云镜像站:TP
2.网易镜像站:TP
3.清华源:TP
4.中科大源:TP