RPM是RedHat Package Manager(RedHat软件包管理工具)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的,现在包括OpenLinux、S.u.S.E.以及Turbo Linux等Linux的分发版本都有采用,可以算是公认的行业标准了。
本文讲解如何管理RPM包。
#安装:i:install v:view h:进度条 [root@serv01 Packages]# rpm -ivh mysql-5.1.52-1.el6_0.1.x86_64.rpm i:install v:view进度条 #rpm -qa query all #查看mysql-server安装包 [root@serv01 Packages]# rpm -qa | grep mysql-server mysql-server-5.1.52-1.el6_0.1.x86_64 #查看mysql-server安装包生成的文件 l:list [root@serv01 Packages]# rpm -ql mysql-server /etc/rc.d/init.d/mysqld #其余文件略 /usr/share/mysql/mysql_test_data_timezone.sql /var/lib/mysql /var/log/mysqld.log /var/run/mysqld #查看安装包生成的文件属于哪个安装包 [root@serv01 ~]# ls /usr/share/mysql/my-medium.cnf /usr/share/mysql/my-medium.cnf [root@serv01 ~]# rpm -qf /usr/share/mysql/my-medium.cnf mysql-server-5.1.52-1.el6_0.1.x86_64 #查看mysql-server安装包的详细信息 [root@serv01 ~]# rpm -qi mysql-server Name : mysql-server Relocations: (not relocatable) Version : 5.1.52 Vendor: Red Hat, Inc. Release : 1.el6_0.1 Build Date: Tue 21 Dec 2010 02:56:53 AM CST Install Date: Sat 27 Jul 2013 12:39:09 AM CST Build Host: x86-006.build.bos.redhat.com Group : Applications/Databases Source RPM: mysql-5.1.52-1.el6_0.1.src.rpm Size : 24481725 License: GPLv2 with exceptions Signature : RSA/8, Mon 17 Jan 2011 09:48:19 PM CST, Key ID 199e2f91fd431d51 Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> URL : http://www.mysql.com Summary : The MySQL server and related files Description : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a client/server implementation consisting of a server daemon (mysqld) and many different client programs and libraries. This package contains the MySQL server and some accompanying files and directories. [root@serv01 Packages]# rpm --help Usage: rpm [OPTION...] --quiet Query/Verify package selection options: -a, --all query/verify all packages -f, --file query/verify package(s) owning file -g, --group query/verify package(s) in group -p, --package query/verify a package file -W, --ftswalk query/verify package(s) from TOP file tree walk --pkgid query/verify package(s) with package identifier --hdrid query/verify package(s) with header identifier --fileid query/verify package(s) with file identifier --specfile query a spec file --triggeredby query the package(s) triggered by the package --whatrequires query/verify the package(s) which require a dependency --whatprovides query/verify the package(s) which provide a dependency --nomanifest do not process non-package files as manifests Query options (with -q or --query): -c, --configfiles list all configuration files -d, --docfiles list all documentation files --dump dump basic file information -l, --list list files in package --queryformat=QUERYFORMAT use the following query format -s, --state display the states of the listed files Verify options (with -V or --verify): --nofiledigest don't verify digest of files --nomd5 don't verify digest of files --nofiles don't verify files in package --nodeps don't verify package dependencies --noscript don't execute verify script(s) File tree walk options (with --ftswalk): --comfollow follow command line symlinks --logical logical walk --nochdir don't change directories --nostat don't get stat info --physical physical walk --seedot return dot and dot-dot --xdev don't cross devices --whiteout return whiteout information Signature options: --addsign sign package(s) (identical to --resign) -K, --checksig verify package signature(s) --delsign delete package signatures --import import an armored public key --resign sign package(s) (identical to --addsign) --nodigest don't verify package digest(s) --nosignature don't verify package signature(s) Database options: --initdb initialize database --rebuilddb rebuild database inverted lists from installed package headers Install/Upgrade/Erase options: --aid add suggested packages to transaction --allfiles install all files, even configurations which might otherwise be skipped --allmatches remove all packages which match <package> (normally an error is generated if <package> specified multiple packages) --badreloc relocate files in non-relocatable package -e, --erase=<package>+ erase (uninstall) package --excludedocs do not install documentation --excludepath=<path> skip files with leading component <path> --fileconflicts detect file conflicts between packages --force short hand for --replacepkgs --replacefiles -F, --freshen=<packagefile>+ upgrade package(s) if already installed -h, --hash print hash marks as package installs (good with -v) --ignorearch don't verify package architecture --ignoreos don't verify package operating system --ignoresize don't check disk space before installing -i, --install install package(s) --justdb update the database, but do not modify the filesystem --nodeps do not verify package dependencies --nofiledigest don't verify digest of files --nomd5 don't verify digest of files (obsolete) --nocontexts don't install file security contexts --noorder do not reorder package installation to satisfy dependencies --nosuggest do not suggest missing dependency resolution(s) --noscripts do not execute package scriptlet(s) --notriggers do not execute any scriptlet(s) triggered by this package --oldpackage upgrade to an old version of the package (--force on upgrades does this automatically) --percent print percentages as package installs --prefix=<dir> relocate the package to <dir>, if relocatable --relocate=<old>=<new> relocate files from path <old> to <new> --replacefiles ignore file conflicts between packages --replacepkgs reinstall if the package is already present --test don't install, but tell if it would work or not -U, --upgrade=<packagefile>+ upgrade package(s) Common options for all rpm modes and executables: -D, --define='MACRO EXPR' define MACRO with value EXPR -E, --eval='EXPR' print macro expansion of EXPR --macros=<FILE:...> read <FILE:...> instead of default file(s) --nodigest don't verify package digest(s) --nosignature don't verify package signature(s) --rcfile=<FILE:...> read <FILE:...> instead of default file(s) -r, --root=ROOT use ROOT as top level directory (default: "/") --querytags display known query tags --showrc display final rpmrc and macro configuration --quiet provide less detailed output -v, --verbose provide more detailed output --version print the version of rpm being used Options implemented via popt alias/exec: --scripts list install/erase scriptlets from package(s) --setperms set permissions of files in a package --setugids set user/group ownership of files in a package --conflicts list capabilities this package conflicts with --obsoletes list other packages removed by installing this package --provides list capabilities that this package provides --requires list capabilities required by package(s) --info list descriptive information from package(s) --changelog list change logs for this package --xml list metadata in xml --triggers list trigger scriptlets from package(s) --last list package(s) by install time, most recent first --dupes list duplicated packages --filesbypkg list all files from each package --fileclass list file names with classes --filecolor list file names with colors --fscontext list file names with security context from file system --fileprovide list file names with provides --filerequire list file names with requires --filecaps list file names with POSIX1.e capabilities Help options: -?, --help Show this help message --usage Display brief usage message #rpm -qa查询所有,再用grep过滤 [root@serv01 ~]# rpm -qa | grep mysql mysql-libs-5.1.52-1.el6_0.1.x86_64 mysql-server-5.1.52-1.el6_0.1.x86_64 mysql-5.1.52-1.el6_0.1.x86_64 #-ql查询安装包里有哪些文件,可以跟包的完整名,或者跟简单名,不能跟msql-5.1.52-1.el6_0.1.x86_64.rpm [root@serv01 ~]# rpm -ql msql-5.1.52-1.el6_0.1.x86_64 #查询mysql RPM包有哪些文件 [root@serv01 ~]# rpm -ql mysql #查询/etc/init.d/mysqld属于哪个安装包 [root@serv01 ~]# rpm -qf /etc/init.d/mysqld mysql-server-5.1.52-1.el6_0.1.x86_64 #查看安装包有哪些文件 [root@serv01 ~]# cp /iso/Packages/mysql-5.1.52-1.el6_0.1.x86_64.rpm . [root@serv01 ~]# rpm -qlp mysql-5.1.52-1.el6_0.1.x86_64.rpm #删除mysqld,再次查看,发现其他文件仍然存在,现在需要重新安装,可以使用--force(强制)和--relacefiles(替换文件)进行安装 [root@serv01 ~]# rm -rf /etc/init.d/mysqld [root@serv01 ~]# ls /etc/init.d/mysql* ls: cannot access /etc/init.d/mysql*: No such file or directory [root@serv01 ~]# rpm -ql mysql [root@serv01 ~]# rpm -ivh /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm warning: /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] package mysql-server-5.1.52-1.el6_0.1.x86_64 is already installed [root@serv01 ~]# rpm -ivh /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm --force warning: /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] 1:mysql-server ########################################### [100%] [root@serv01 ~]# rpm -ivh /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm --force --replacefiles warning: /iso/Packages/mysql-server-5.1.52-1.el6_0.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] 1:mysql-server ########################################### [100%] #RPM包有依赖关系,可以使用--nodeps进行安装,但基本上不能使用 [root@serv01 ~]# rpm -ivh /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm warning: /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: apr-util-ldap is needed by httpd-2.2.15-9.el6.x86_64 httpd-tools = 2.2.15-9.el6 is needed by httpd-2.2.15-9.el6.x86_64 [root@serv01 ~]# rpm -qa | grep httpd [root@serv01 ~]# rpm -ivh /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm --force warning: /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: apr-util-ldap is needed by httpd-2.2.15-9.el6.x86_64 httpd-tools = 2.2.15-9.el6 is needed by httpd-2.2.15-9.el6.x86_64 [root@serv01 ~]# rpm -ivh /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm --force --nodeps warning: /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] 1:httpd ########################################### [100%] #可以发现不能正常使用 [root@serv01 ~]# /etc/init.d/httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for serv01.host.com #卸载httpd [root@serv01 ~]# rpm -e httpd #再次查看发现不能查找到 [root@serv01 ~]# rpm -qa|grep httpd #抛掉依赖,卸载时加上--nodeps [root@serv01 ~]# rpm -e mysql error: Failed dependencies: mysql = 5.1.52-1.el6_0.1 is needed by (installed) mysql-server-5.1.52-1.el6_0.1.x86_64 [root@serv01 ~]# rpm -e mysql --force rpm: only installation, upgrading, rmsource and rmspec may be forced [root@serv01 ~]# rpm -e mysql --force --nodeps rpm: only installation, upgrading, rmsource and rmspec may be forced [root@serv01 ~]# rpm -e mysql --nodeps [root@serv01 ~]# /etc/init.d/mysqld start /etc/init.d/mysqld: line 37: /usr/bin/my_print_defaults: No such file or directory [root@serv01 ~]# rpm -e --nodeps mysql #软件升级 [root@larrywen ule-sa1]# cd package-manager/ [root@larrywen package-manager]# ll total 41708 -rwxr-xr-x. 1 root root 38572579 Jul 24 09:52 mongodb-linux-x86_64-2.0.6.tgz -rwxr-xr-x. 1 root root 2871736 Jul 24 09:52 nagios-3.2.3-8.el6.x86_64.rpm -rwxr-xr-x. 1 root root 1223472 Jul 24 09:52 nagios-3.4.1-2.el6.x86_64.rpm -rwxr-xr-x. 1 root root 14720 Jul 24 09:52 nagios-common-3.2.3-8.el6.x86_64.rpm -rwxr-xr-x. 1 root root 16204 Jul 24 09:52 nagios-common-3.4.1-2.el6.x86_64.rpm #拷贝nagios-*包含的文件到虚拟机下的/root目录下 [root@larrywen package-manager]# scp nagios-* 192.168.1.11:/root root@192.168.1.11's password: nagios-3.2.3-8.el6.x86_64.rpm 100% 2804KB 2.7MB/s 00:00 nagios-3.4.1-2.el6.x86_64.rpm 100% 1195KB 1.2MB/s 00:00 nagios-common-3.2.3-8.el6.x86_64.rpm 100% 14KB 14.4KB/s 00:00 nagios-common-3.4.1-2.el6.x86_64.rpm 100% 16KB 15.8KB/s 00:00 #安装nagios-3.2.3-8.el6.x86_64.rpm,如果缺少依赖则把缺少的安装上 [root@serv01 ~]# rpm -ivh nagios-3.2.3-8.el6.x86_64.rpm warning: nagios-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY error: Failed dependencies: group(nagios) is needed by nagios-3.2.3-8.el6.x86_64 httpd is needed by nagios-3.2.3-8.el6.x86_64 libgd.so.2()(64bit) is needed by nagios-3.2.3-8.el6.x86_64 mailx is needed by nagios-3.2.3-8.el6.x86_64 nagios-common is needed by nagios-3.2.3-8.el6.x86_64 user(nagios) is needed by nagios-3.2.3-8.el6.x86_64 #把httpd安装上 [root@serv01 ~]# rpm -qa|grep httpd [root@serv01 ~]# rpm -ivh /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm --nodeps warning: /iso/Packages/httpd-2.2.15-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] 1:httpd ########################################### [100%] #把mailx安装上 [root@serv01 ~]# rpm -ivh /iso/Packages/mailx-12.4-6.el6.x86_64.rpm warning: /iso/Packages/mailx-12.4-6.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ########################################### [100%] 1:mailx ########################################### [100%] #再次安装,仍然有依赖问题 [root@serv01 ~]# rpm -ivh nagios-3.2.3-8.el6.x86_64.rpm warning: nagios-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY error: Failed dependencies: group(nagios) is needed by nagios-3.2.3-8.el6.x86_64 libgd.so.2()(64bit) is needed by nagios-3.2.3-8.el6.x86_64 nagios-common is needed by nagios-3.2.3-8.el6.x86_64 user(nagios) is needed by nagios-3.2.3-8.el6.x86_64 #把nagios-common安装上 [root@serv01 ~]# rpm -ivh nagios-common-3.2.3-8.el6.x86_64.rpm warning: nagios-common-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] #再次安装,发现缺少libgd.so库 [root@serv01 ~]# rpm -ivh nagios-3.2.3-8.el6.x86_64.rpm warning: nagios-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY error: Failed dependencies: libgd.so.2()(64bit) is needed by nagios-3.2.3-8.el6.x86_64 #通过yum源解决依赖问题 [root@serv01 ~]# yum install /usr/lib64/libgd.so* -y [root@serv01 ~]# yum install httpd -y #查询,发现安装成功 [root@serv01 ~]# rpm -qa|grep nagios nagios-common-3.2.3-8.el6.x86_64 nagios-3.2.3-8.el6.x86_64 #升级nagios [root@serv01 ~]# rpm -Uvh nagios-3.4.1-2.el6.x86_64.rpm warning: nagios-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY error: Failed dependencies: php is needed by nagios-3.4.1-2.el6.x86_64 #通过yum源安装php [root@serv01 ~]# yum install php* -y #再次升级 -U参数 [root@serv01 ~]# rpm -Uvh nagios-3.4.1-2.el6.x86_64.rpm warning: nagios-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios ########################################### [100%] [root@serv01 ~]# rpm -Uvh nagios-common-3.4.1-2.el6.x86_64.rpm warning: nagios-common-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] #升级成功 [root@serv01 ~]# rpm -qa|grep nagios nagios-common-3.4.1-2.el6.x86_64 nagios-3.4.1-2.el6.x86_64 #卸载 [root@serv01 ~]# rpm -e nagios [root@serv01 ~]# rpm -e nagios-common [root@serv01 ~]# rpm -qa|grep nagios #再次安装低版本 [root@serv01 ~]# rpm -ivh nagios-common-3.2.3-8.el6.x86_64.rpm warning: nagios-common-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] [root@serv01 ~]# rpm -ivh nagios-3.2.3-8.el6.x86_64.rpm warning: nagios-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios ########################################### [100%] #通过-F参数升级 [root@serv01 ~]# rpm -Fvh nagios-3.4.1-2.el6.x86_64.rpm warning: nagios-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios ########################################### [100%] [root@serv01 ~]# rpm -Fvh nagios-common-3.4.1-2.el6.x86_64.rpm warning: nagios-common-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] [root@serv01 ~]# rpm -qa|grep nagios nagios-common-3.4.1-2.el6.x86_64 nagios-3.4.1-2.el6.x86_64 #安装时不校验,加--nosignature参数 [root@serv01 ~]# rpm -Uvh nagios-common-3.4.1-2.el6.x86_64.rpm --nosignature #-F和-U的区别 #-F:没有低版本,不能升级,如果有,就升级 #-U:没有低版本,就安装上,如果有,就升级 [root@serv01 ~]# rpm -ivh nagios-common-3.2.3-8.el6.x86_64.rpm warning: nagios-common-3.2.3-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] [root@serv01 ~]# rpm -Uvh nagios-common-3.4.1-2.el6.x86_64.rpm warning: nagios-common-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] [root@serv01 ~]# rpm -qa|grep nagios nagios-common-3.4.1-2.el6.x86_64 [root@serv01 ~]# rpm -e nagios-common [root@serv01 ~]# rpm -Fvh nagios-common-3.4.1-2.el6.x86_64.rpm warning: nagios-common-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY [root@serv01 ~]# rpm -qa|grep nagios [root@serv01 ~]# rpm -Uvh nagios-common-3.4.1-2.el6.x86_64.rpm warning: nagios-common-3.4.1-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:nagios-common ########################################### [100%] [root@serv01 ~]# rpm -qa|grep nagios-common nagios-common-3.4.1-2.el6.x86_64
参考资料:http://baike.baidu.com/view/209700.htm
我的邮箱:wgbno27@163.com 新浪微博:@Wentasy27 微信公众平台:JustOracle(微信号:justoracle) 数据库技术交流群:336882565(加群时验证 From CSDN XXX) Oracle交流讨论组:https://groups.google.com/d/forum/justoracle By Larry Wen
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |