rpm管理器常用方法
1.光盘挂载
1)需要先执行:
yum -y install autofs
[root@centos7 ~]# rpm -q autofs
autofs-5.0.7-116.el7_9.x86_64
2)然后在执行:
[root@centos7 ~]# systemctl enable --now autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
3)第三步进入到misc的cd中用df查看:
[root@centos7 ~]# ls /misc [root@centos7 ~]# cd /misc/cd [root@centos7 cd]# pwd /misc/cd [root@centos7 cd]# ls CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL [root@centos7 cd]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 915780 0 915780 0% /dev tmpfs 931512 0 931512 0% /dev/shm tmpfs 931512 10688 920824 2% /run tmpfs 931512 0 931512 0% /sys/fs/cgroup /dev/sda2 52403200 5030532 47372668 10% / /dev/sda3 31441920 395068 31046852 2% /data /dev/sda1 1038336 184100 854236 18% /boot tmpfs 186304 36 186268 1% /run/user/0 /dev/sr0 9961428 9961428 0 100% /misc/cd
就可以看到sro被关联到/misc/cd里。
4)在这个目录中,你要看哪个文件最大,用这个命令:
[root@centos7 cd]# du -sh * 512 CentOS_BuildTag 8.4M EFI 512 EULA 18K GPL 68M images 60M isolinux 498M LiveOS 9.0G Packages 29M repodata 2.0K RPM-GPG-KEY-CentOS-7 2.0K RPM-GPG-KEY-CentOS-Testing-7 3.0K TRANS.TBL
5)然后我们进入到baseOs目录中的Packages目录中(centOS8),centOS7直接进入Packages:
[root@centos7 cd]# cd Packages
[root@centos7 Packages]#
你会发现这里就是放rpm包的
2.我如何查自己系统是64位还是32位的:
[root@centos7 Packages]# arch
x86_64
3.我想统计x86_64有多少个,i686有多少个:
第一种方法:
[root@centos7 Packages]# ls *.rpm | rev | cut -d. -f2 | rev | sort | uniq -c 2268 i686 3154 noarch 4650 x86_64
第二种方法:
[root@centos7 Packages]# ls *.rpm | sed -rn 's/.*\.([^.]+)\.rpm$/\1/p' | sort |uniq -c 2268 i686 3154 noarch 4650 x86_64
4.rpm2cpio,这个命令是将rpm文件转为cpio流,之后就能看见文件内容了。
[root@centos7 Packages]# rpm2cpio xfsprogs-4.5.0-22.el7.i686.rpm | cpio -tv lrwxrwxrwx 1 root root 18 Oct 1 2020 ./usr/lib/libhandle.so.1 -> libhandle.so.1.0.3 -rwxr-xr-x 1 root root 14916 Oct 1 2020 ./usr/lib/libhandle.so.1.0.3 -rwxr-xr-x 1 root root 433 Oct 1 2020 ./usr/sbin/fsck.xfs -rwxr-xr-x 1 root root 408216 Oct 1 2020 ./usr/sbin/mkfs.xfs -rwxr-xr-x 1 root root 1380 Oct 1 2020 ./usr/sbin/xfs_admin -rwxr-xr-x 1 root root 638 Oct 1 2020 ./usr/sbin/xfs_bmap -rwxr-xr-x 1 root root 383548 Oct 1 2020 ./usr/sbin/xfs_copy -rwxr-xr-x 1 root root 621644 Oct 1 2020 ./usr/sbin/xfs_db -rwxr-xr-x 1 root root 10724 Oct 1 2020 ./usr/sbin/xfs_estimate -rwxr-xr-x 1 root root 767 Oct 1 2020 ./usr/sbin/xfs_freeze -rwxr-xr-x 1 root root 31664 Oct 1 2020 ./usr/sbin/xfs_fsr -rwxr-xr-x 1 root root 367044 Oct 1 2020 ./usr/sbin/xfs_growfs -rwxr-xr-x 1 root root 472 Oct 1 2020 ./usr/sbin/xfs_info -rwxr-xr-x 1 root root 132484 Oct 1 2020 ./usr/sbin/xfs_io -rwxr-xr-x 1 root root 400304 Oct 1 2020 ./usr/sbin/xfs_logprint -rwxr-xr-x 1 root root 350260 Oct 1 2020 ./usr/sbin/xfs_mdrestore -rwxr-xr-x 1 root root 747 Oct 1 2020 ./usr/sbin/xfs_metadump -rwxr-xr-x 1 root root 1007 Oct 1 2020 ./usr/sbin/xfs_mkfile -rwxr-xr-x 1 root root 650 Oct 1 2020 ./usr/sbin/xfs_ncheck -rwxr-xr-x 1 root root 90136 Oct 1 2020 ./usr/sbin/xfs_quota -rwxr-xr-x 1 root root 641100 Oct 1 2020 ./usr/sbin/xfs_repair -rwxr-xr-x 1 root root 14876 Oct 1 2020 ./usr/sbin/xfs_rtcp drwxr-xr-x 2 root root 0 Oct 1 2020 ./usr/share/doc/xfsprogs-4.5.0 -rw-r--r-- 1 root root 76633 Mar 15 2016 ./usr/share/doc/xfsprogs-4.5.0/CHANGES -rw-r--r-- 1 root root 63071 Dec 31 2009 ./usr/share/doc/xfsprogs-4.5.0/COPYING -rw-r--r-- 1 root root 2032 Dec 31 2009 ./usr/share/doc/xfsprogs-4.5.0/CREDITS -rw-r--r-- 1 root root 362 Oct 1 2020 ./usr/share/doc/xfsprogs-4.5.0/README -rw-r--r-- 1 root root 333016 Oct 1 2020 ./usr/share/locale/de/LC_MESSAGES/xfsprogs.mo -rw-r--r-- 1 root root 343651 Oct 1 2020 ./usr/share/locale/pl/LC_MESSAGES/xfsprogs.mo -rw-r--r-- 1 root root 371 Oct 1 2020 ./usr/share/man/man5/projects.5.gz -rw-r--r-- 1 root root 376 Oct 1 2020 ./usr/share/man/man5/projid.5.gz -rw-r--r-- 1 root root 4766 Oct 1 2020 ./usr/share/man/man5/xfs.5.gz -rw-r--r-- 1 root root 371 Oct 1 2020 ./usr/share/man/man8/fsck.xfs.8.gz -rw-r--r-- 1 root root 8011 Oct 1 2020 ./usr/share/man/man8/mkfs.xfs.8.gz -rw-r--r-- 1 root root 1429 Oct 1 2020 ./usr/share/man/man8/xfs_admin.8.gz -rw-r--r-- 1 root root 1066 Oct 1 2020 ./usr/share/man/man8/xfs_bmap.8.gz -rw-r--r-- 1 root root 1807 Oct 1 2020 ./usr/share/man/man8/xfs_copy.8.gz -rw-r--r-- 1 root root 13121 Oct 1 2020 ./usr/share/man/man8/xfs_db.8.gz -rw-r--r-- 1 root root 839 Oct 1 2020 ./usr/share/man/man8/xfs_estimate.8.gz -rw-r--r-- 1 root root 1005 Oct 1 2020 ./usr/share/man/man8/xfs_freeze.8.gz -rw-r--r-- 1 root root 2230 Oct 1 2020 ./usr/share/man/man8/xfs_fsr.8.gz -rw-r--r-- 1 root root 1996 Oct 1 2020 ./usr/share/man/man8/xfs_growfs.8.gz lrwxrwxrwx 1 root root 15 Oct 1 2020 ./usr/share/man/man8/xfs_info.8.gz -> xfs_growfs.8.gz -rw-r--r-- 1 root root 6741 Oct 1 2020 ./usr/share/man/man8/xfs_io.8.gz -rw-r--r-- 1 root root 1251 Oct 1 2020 ./usr/share/man/man8/xfs_logprint.8.gz -rw-r--r-- 1 root root 606 Oct 1 2020 ./usr/share/man/man8/xfs_mdrestore.8.gz -rw-r--r-- 1 root root 1842 Oct 1 2020 ./usr/share/man/man8/xfs_metadump.8.gz -rw-r--r-- 1 root root 462 Oct 1 2020 ./usr/share/man/man8/xfs_mkfile.8.gz -rw-r--r-- 1 root root 872 Oct 1 2020 ./usr/share/man/man8/xfs_ncheck.8.gz -rw-r--r-- 1 root root 6862 Oct 1 2020 ./usr/share/man/man8/xfs_quota.8.gz -rw-r--r-- 1 root root 5425 Oct 1 2020 ./usr/share/man/man8/xfs_repair.8.gz -rw-r--r-- 1 root root 635 Oct 1 2020 ./usr/share/man/man8/xfs_rtcp.8.gz 8519 blocks
5.接下来,我们怎么使用这个包哪,我们需要使用一个工具叫包管理器,红帽就用的rpm这个命令
6.rpm本身也是一个二进制程序
[root@centos7 Packages]# type rpm rpm is hashed (/usr/bin/rpm) [root@centos7 Packages]# file /usr/bin/rpm /usr/bin/rpm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=96ecb31da995195563a0ed95d906fb3c0415e866, strippe
7.程序包管理相关文件
1)包文件组成(每个包独有)
包内文件
元数据,如:包的名称,版本,依赖性,描述等
可能会有包安装或卸载时运行的脚本
2)数据库(公共):/var/lib/rpm
程序包名称及版本
依赖关系
功能说明
包安装后生成的个文件路径及校验码信息
8.我们如何知道这个包是否带脚本?
[root@centos7 Packages]# rpm -qp --scripts httpd-2.4.6-95.el7.centos.x86_64.rpm preinstall scriptlet (using /bin/sh): # Add the "apache" group and user /usr/sbin/groupadd -g 48 -r apache 2> /dev/null || : /usr/sbin/useradd -c "Apache" -u 48 -g apache \ -s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || : postinstall scriptlet (using /bin/sh): if [ $1 -eq 1 ] ; then # Initial installation systemctl preset httpd.service htcacheclean.service >/dev/null 2>&1 || : fi preuninstall scriptlet (using /bin/sh): if [ $1 -eq 0 ] ; then # Package removal, not upgrade systemctl --no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || : systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || : fi postuninstall scriptlet (using /bin/sh): systemctl daemon-reload >/dev/null 2>&1 || : # Trigger for conversion from SysV, per guidelines at: # https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd posttrans scriptlet (using /bin/sh): test -f /etc/sysconfig/httpd-disable-posttrans || \ /bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :
9.另外,我们安装管理包后,它有一个公共的数据,我们只要安装软件包,它就会把公共的信息放在数据库里面,叫/var/lib/rpm
[root@centos7 Packages]# ls /var/lib/rpm Basenames __db.001 __db.003 Group Name Packages Requirename Sigmd5 Conflictname __db.002 Dirnames Installtid Obsoletename Providename Sha1header Triggername
这个文件很重要的,只要我们安装软件包,他就会把每个安装好的包以及这个包里面包含的文件列表都会放在这个文件夹里,记录下来.
将来我们可以用这个数据库,就可以知道系统装了那些包,这些包涵盖那些文件,包括属性.
10.想知道一个软件装没装可以用这个命令来查看:
[root@centos7 Packages]# rpm -q vsftpd package vsftpd is not installed [root@centos7 Packages]# echo $? 1
可配合脚本使用,返回的结果非零说明他没有安装
11.安装任意rpm包:
[root@centos7 Packages]# rpm -ivh vsftpd-3.0.2-28.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-28.el7 ################################# [100%]
其实安装vh可以不用写,但是为了更直观的看到安装的过程,所以建议加上
再次确认是否装上了:
[root@centos7 Packages]# rpm -p vsftpd RPM version 4.11.3 Copyright (C) 1998-2002 - Red Hat, Inc. This program may be freely redistributed under the terms of the GNU GPL Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group] [-p|--package] [--pkgid] [--hdrid] [--triggeredby] [--whatrequires] [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles] [-L|--licensefiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] [--nofiledigest] [--nofiles] [--nodeps] [--noscript] [--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+] [--excludedocs] [--excludepath=<path>] [--force] [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos] [--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest] [--nocontexts] [--noorder] [--noscripts] [--notriggers] [--nocollections] [--oldpackage] [--percent] [--prefix=<dir>] [--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test] [-U|--upgrade <packagefile>+] [--reinstall=<packagefile>+] [-D|--define 'MACRO EXPR'] [--undefine=MACRO] [-E|--eval 'EXPR'] [--macros=<FILE:...>] [--noplugins] [--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT] [--dbpath=DIRECTORY] [--querytags] [--showrc] [--quiet] [-v|--verbose] [--version] [-?|--help] [--usage] [--scripts] [--setperms] [--setugids] [--setcaps] [--restore] [--conflicts] [--obsoletes] [--provides] [--requires] [--info] [--changelog] [--xml] [--triggers] [--last] [--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext] [--fileprovide] [--filerequire] [--filecaps]
12.当然,会安装也要回卸载:
[root@centos7 Packages]# rpm -e vsftpd [root@centos7 Packages]# rpm -q vsftpd package vsftpd is not installed
注意卸载的时候,光写软件的名称就行了,用不着写文件名了,我们装的时候移动要写文件名以及路径的!
13.我很想知道包内那么多文件上哪去了,有一个方法:
[root@centos7 Packages]# rpm -ql tree /usr/bin/tree /usr/share/doc/tree-1.6.0 /usr/share/doc/tree-1.6.0/LICENSE /usr/share/doc/tree-1.6.0/README /usr/share/man/man1/tree.1.gz
ql 可以查询一个已经装好的包,它包含的文件以及分别那个目录下。
14.另外我们还可以查包的信息,用qi:
[root@centos7 Packages]# rpm -ql tree /usr/bin/tree /usr/share/doc/tree-1.6.0 /usr/share/doc/tree-1.6.0/LICENSE /usr/share/doc/tree-1.6.0/README /usr/share/man/man1/tree.1.gz [root@centos7 Packages]# rpm -qi tree Name : tree Version : 1.6.0 Release : 10.el7 Architecture: x86_64 Install Date: Fri 07 Jan 2022 01:47:08 PM CST Group : Applications/File Size : 89505 License : GPLv2+ Signature : RSA/SHA256, Fri 04 Jul 2014 01:36:46 PM CST, Key ID 24c6a8a7f4a80eb5 Source RPM : tree-1.6.0-10.el7.src.rpm Build Date : Tue 10 Jun 2014 03:28:53 AM CST Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://mama.indstate.edu/users/ice/tree/ Summary : File system tree viewer Description : The tree utility recursively displays the contents of directories in a tree-like format. Tree is basically a UNIX port of the DOS tree utility.
15.-qf:和ql相反,他是查看磁盘上的文件来自那个包
[root@centos7 Packages]# rpm -qf /etc/issue centos-release-7-9.2009.0.el7.centos.x86_64
16.我们还可以挑着查:
1)-qc 只查看包的配置文件
[root@centos7 Packages]# rpm -qc vsftpd /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf
2)-qd:只看文档
[root@centos7 Packages]# rpm -qd vsftpd /usr/share/doc/vsftpd-3.0.2/AUDIT /usr/share/doc/vsftpd-3.0.2/BENCHMARKS /usr/share/doc/vsftpd-3.0.2/BUGS /usr/share/doc/vsftpd-3.0.2/COPYING /usr/share/doc/vsftpd-3.0.2/Changelog /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.xinetd /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/hosts.allow /usr/share/doc/vsftpd-3.0.2/EXAMPLE/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_HOSTS/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/logins.txt /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/vsftpd.pam /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS_2/README /usr/share/doc/vsftpd-3.0.2/FAQ /usr/share/doc/vsftpd-3.0.2/INSTALL /usr/share/doc/vsftpd-3.0.2/LICENSE /usr/share/doc/vsftpd-3.0.2/README /usr/share/doc/vsftpd-3.0.2/README.security /usr/share/doc/vsftpd-3.0.2/REWARD /usr/share/doc/vsftpd-3.0.2/SECURITY/DESIGN /usr/share/doc/vsftpd-3.0.2/SECURITY/IMPLEMENTATION /usr/share/doc/vsftpd-3.0.2/SECURITY/OVERVIEW /usr/share/doc/vsftpd-3.0.2/SECURITY/TRUST /usr/share/doc/vsftpd-3.0.2/SIZE /usr/share/doc/vsftpd-3.0.2/SPEED /usr/share/doc/vsftpd-3.0.2/TODO /usr/share/doc/vsftpd-3.0.2/TUNING /usr/share/doc/vsftpd-3.0.2/vsftpd.xinetd /usr/share/man/man5/vsftpd.conf.5.gz /usr/share/man/man8/vsftpd.8.gz
17.总的,rpm: -i:安装,-e:卸载,-q:查询
rpm主流的应用也就这么多,实际上安装卸载我们也不用,因为安装卸载存在依赖关系问题