一、概念简介
RPM 全名是『 RedHat Package Manager 』简称则为 RPM,是以一种数据库记录的方式来将你所需要的套件安装到你的 Linux 主机的一套管理程序。
二、实验环境
本地主机:ip地址为192.168.0.1,主要用于安装、调试、卸载软件包用 远程主机:含已给出的共享目录,本地主机可以挂载远程主机给出的共享,方便文件安装,ip地址为192.168.0.254
三、实例演示
1.查看远程主机已共享目录信息
[root@desktop1 ~]# showmount -e 192.168.0.254 Export list for 192.168.0.254: /nfstest 192.168.0.0/24 /var/ftp/pub/iso 192.168.0.0/24 /iso 192.168.0.0/24 /var/ftp/pub/rhel7/dvd 192.168.0.0/24 /kickstart 192.168.0.0/24 /rhome 192.168.0.0/24 /home/guests 192.168.0.0/24 /var/ftp/pub 192.168.0.0/24
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 3.0G 46G 7% / devtmpfs 905M 0 905M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 9.0M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/mapper/vol0-home 509M 26M 483M 6% /home /dev/sda1 497M 104M 394M 21% /boot /dev/sr0 3.8G 3.8G 0 100% /run/media/root/RHEL-7.2 Server.x86_64 192.168.0.254:/var/ftp/pub/rhel7 20G 340M 20G 2% /rhel7
3. 使用rpm ivh 命令安装bind-9.9.4-14.el7.x86_64.rpm(本地已经安装了,并且该安装包无其他依赖包)
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/bind-9.9.4-14.el7.x86_64.rpm warning: /rhel7/dvd/Packages/bind-9.9.4-14.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] package bind-32:9.9.4-14.el7.x86_64 is already installed
4. 安装有其他依赖的rpm包会提示缺少依赖项,该示例显示安装tftp-server时需要用到xinetd包。
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm warning: /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: xinetd is needed by tftp-server-5.2-11.el7.x86_64
5. 使用 rpm –ivh 先安装 tftp-server 的依赖包 xinetd,再安装 tftp-server
[root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/xinetd-2.3.15-12.el7.x86_64.rpm warning: /rhel7/dvd/Packages/xinetd-2.3.15-12.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:xinetd-2:2.3.15-12.el7 ################################# [100%] [root@desktop1 ~]# rpm -ivh /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm warning: /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:tftp-server-5.2-11.el7 ################################# [100%]
6. 使用 rpm 命令,检查tftp-server-5.2-11.el7.x86_64.rpm这个包的信息(可以看到版本,名字、适用架构等)
[root@desktop1 ~]# rpm -qpi /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm warning: /rhel7/dvd/Packages/tftp-server-5.2-11.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Name : tftp-server Version : 5.2 Release : 11.el7 Architecture: x86_64 Install Date: (not installed) Group : System Environment/Daemons Size : 65505 License : BSD Signature : RSA/SHA256, Thu 03 Apr 2014 05:21:51 AM CST, Key ID 199e2f91fd431d51 Source RPM : tftp-5.2-11.el7.src.rpm Build Date : Tue 28 Jan 2014 12:21:22 AM CST Build Host : x86-021.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-11.el7.x86_64.rpm warning: /rhel7/dvd/Packages/tftp-server-5.2-11.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.8.gz /usr/share/man/man8/tftpd.8.gz /var/lib/tftpboot
8. 用 rpm 命令,检查/etc/named.conf 是由哪个 rpm 包生成的
[root@desktop1 ~]# rpm -qf /etc/named.conf bind-9.9.4-14.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-11.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.4-14.el7.x86_64.rpm /rhel7/dvd/Packages/bind-9.9.4-14.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.4-14.el7.x86_64.rpm /tmp [root@desktop1 ~]# echo 123 >> /tmp/bind-9.9.4-14.el7.x86_64.rpm [root@desktop1 ~]# rpm -K /tmp/bind-9.9.4-14.el7.x86_64.rpm /tmp/bind-9.9.4-14.el7.x86_64.rpm: rsa sha1 (MD5) PGP MD5 NOT OK