一、概念简介
RPM 全名是『 RedHat Package Manager 』简称则为 RPM,是以一种数据库记录的方式来将你所需要的套件安装到你的 Linux 主机的一套管理程序。
二、实验环境
本地主机:ip地址为192.168.0.,主要用于安装、调试、卸载软件包用 远程主机:含已给出的共享目录,本地主机可以挂载远程主机给出的共享,方便文件安装,ip地址为192.168.0.
三、实例演示
1.查看远程主机已共享目录信息
[root@desktop1 ~]# showmount -e 192.168.0.254
Export list for 192.168.0.254:
/nfstest 192.168.0.0/
/var/ftp/pub/iso 192.168.0.0/
/iso 192.168.0.0/
/var/ftp/pub/rhel7/dvd 192.168.0.0/
/kickstart 192.168.0.0/
/rhome 192.168.0.0/
/home/guests 192.168.0.0/
/var/ftp/pub 192.168.0.0/
2.在本地创建/rhel7目录,并将远程主机192.168.0.254的/var/ftp/pub/rhel7目录挂载到本地/rhel7目录,方便后续实验
[root@desktop1 ~]# mkdir /rhel7
[root@desktop1 ~]# mount 192.168.0.254:/var/ftp/pub/rhel7 /rhel7
[root@desktop1 ~]# df -h # 查看挂载情况,最后一行显示已挂载成功
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root 49G .0G 46G % /
devtmpfs 905M 905M % /dev
tmpfs 914M 140K 914M % /dev/shm
tmpfs 914M 9.0M 905M % /run
tmpfs 914M 914M % /sys/fs/cgroup
/dev/mapper/vol0-home 509M 26M 483M % /home
/dev/sda1 497M 104M 394M % /boot
/dev/sr0 .8G .8G % /run/media/root/RHEL-7.2 Server.x86_64
192.168.0.254:/var/ftp/pub/rhel7 20G 340M 20G % /rhel7
3. 使用rpm ivh 命令安装bind-9.9.4-14.el7.x86_64.rpm(本地已经安装了,并且该安装包无其他依赖包)
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/bind-9.9.-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/bind-9.9.-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [%]
package bind-:9.9.-.el7.x86_64 is already installed
4. 安装有其他依赖的rpm包会提示缺少依赖项,该示例显示安装tftp-server时需要用到xinetd包。
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
xinetd is needed by tftp-server-5.2-.el7.x86_64
5. 使用 rpm –ivh 先安装 tftp-server 的依赖包 xinetd,再安装 tftp-server
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/xinetd-2.3.-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/xinetd-2.3.-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [%]
Updating / installing...
:xinetd-:2.3.-.el7 ################################# [%]
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [%]
Updating / installing...
:tftp-server-5.2-.el7 ################################# [%]
6. 使用 rpm 命令,检查tftp-server-5.2-11.el7.x86_64.rpm这个包的信息(可以看到版本,名字、适用架构等)
[root@desktop1 ~]# rpm -qpi /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Name : tftp-server
Version : 5.2
Release : .el7
Architecture: x86_64
Install Date: (not installed)
Group : System Environment/Daemons
Size :
License : BSD
Signature : RSA/SHA256, Thu Apr :: AM CST, Key ID 199e2f91fd431d51
Source RPM : tftp-5.2-.el7.src.rpm
Build Date : Tue Jan :: AM CST
Build Host : x86-.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor : Red Hat, Inc.
URL : http://www.kernel.org/pub/software/network/tftp/
Summary : The server for the Trivial File Transfer Protocol (TFTP)
Description :
The Trivial File Transfer Protocol (TFTP) is normally used only for
booting diskless workstations. The tftp-server package provides the
server for TFTP, which allows users to transfer files to and from a
remote machine. TFTP provides very little security, and should not be
enabled unless it is expressly needed. The TFTP server is run from
/etc/xinetd.d/tftp, and is disabled by default.
7.使用 rpm 命令,检查/rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm这个软件包安装后在系统中会创建的文件
[root@desktop1 ~]# rpm -qpl /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm
warning: /rhel7/dvd/Packages/tftp-server-5.2-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd..gz
/usr/share/man/man8/tftpd..gz
/var/lib/tftpboot
8. 用 rpm 命令,检查/etc/named.conf 是由哪个 rpm 包生成的
[root@desktop1 ~]# rpm -qf /etc/named.conf
bind-9.9.-.el7.x86_64
9. 使用rpm卸载bind这个软件包
[root@desktop1 ~]# rpm -e bind
10. 再次查看/etc/named.conf这个文件,已被删除。
[root@desktop1 ~]# rpm -qf /etc/named.conf
error: file /etc/named.conf: No such file or directory
11. 使用rpm命令删除xinetd,删除不成功,还有tftp-server依赖项,所以删除不了。
[root@desktop1 ~]# rpm -e xinetd
error: Failed dependencies:
xinetd is needed by (installed) tftp-server-5.2-.el7.x86_64
12. 使用rpm命令先卸载tftp-server,xinetd
[root@desktop1 ~]# rpm -e tftp-server xinetd
13. 使用 rpm –import 导入/rhel7/dvd/RPM-GPG-KEY-redhat-release 这个用于验证 RPM包签名的公钥文件
[root@desktop1 ~]# rpm --import /rhel7/dvd/RPM-GPG-KEY-redhat-release
14. 使用rpm -K 验证bind-9.9.4-14.el7.x86_64.rpm,看到显示md5 OK
[root@desktop1 ~]# rpm -K /rhel7/dvd/Packages/bind-9.9.-.el7.x86_64.rpm
/rhel7/dvd/Packages/bind-9.9.-.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK
15. 将bind-9.9.4-14.el7.x86_64.rpm复制到/tmp目录下,在尾部添加123后再次使用rpm -K确认,显示MD5 NOT OK"
[root@desktop1 ~]# cp /rhel7/dvd/Packages/bind-9.9.-.el7.x86_64.rpm /tmp
[root@desktop1 ~]# echo >> /tmp/bind-9.9.-.el7.x86_64.rpm
[root@desktop1 ~]# rpm -K /tmp/bind-9.9.-.el7.x86_64.rpm
/tmp/bind-9.9.-.el7.x86_64.rpm: rsa sha1 (MD5) PGP MD5 NOT OK