【yum和rpm】个人用到的方法记录

2016/11/15

yum和rpm博大精深,本人除了简单的用法,其他的在工作中尚未深入研究。1、搜索和查询yum search zabbix使用指定的repo源来搜索:yum search --disablerepo='*' --enablerepo=office zabbix   查询系统安装的rpm包:rpm -qa |grep mysql查询rpm包是否有bugfix:rpm -q --changelog openssl |more查询某个rpm内的文件列表:[root@tvm-saltmaster pkgs]# rpm -qpl office-repo-latest-6-1.el6.x86_64.rpm /etc/yum.repos.d/local-office.repo查询某个rpm内的信息:[root@tvm-saltmaster pkgs]# rpm -qpi office-repo-latest-6-1.el6.x86_64.rpm  Name        : office-repo-latest           Relocations: / Version     : 6                                 Vendor: pc@officeRelease     : 1.el6                         Build Date: Thu 06 Aug 2015 04:53:26 PM CSTInstall Date: (not installed)               Build Host: tvm-saltmasterGroup       : default                       Source RPM: office-repo-latest-6-1.el6.src.rpmSize        : 2392                             License: unknownSignature   : (none)Packager    : PCURL         : http://example.com/no-uri-givenSummary     : provide file: [local-office.repo] for local users. include: centos-base, eple, user-define rpmsDescription :provide file: [local-office.repo] for local users. include: centos-base, eple, user-define rpms2、安装yum install lrzsz screenyum groupinstall "Development Tools"yum --enablerepo=epel install iftop安装本地的rpm文件:rpm -ivh xxx.rpm  --nodeps参数,不检查软件间的依赖关系:rpm -ivh --nodeps xxx.rpm 3、更新yum -y update openssl若yum udpate时,提示超时,Errno 12 然后再update时提示没有可用的升级包,No Packages marked for Update不妨试试:yum clean allyum makecache更新某个rpm包:rpm -Uvh xxx.rpm  4、卸载yum remove lrzsz若遇到依赖关系,也可以强制删除:rpm -e --nodeps xxx 5、使用 yum-plugin-downloadonly 这个插件,通过仅下载 rpm 包的方式来缓存为本地 yum 源本例以安装 fio 为例:[root@vm49 ~]# yum install yum-plugin-downloadonly -y[root@vm49 ~]# yum install --downloadonly --downloaddir=/var/www/html/repo/ fioLoaded plugins: downloadonly, fastestmirror, securityLoading mirror speeds from cached hostfileSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package fio.x86_64 0:2.0.13-1.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved=================================================================== Package        Arch        Version        Repository        Size===================================================================Installing: fio        x86_64        2.0.13-1.el6        epel        222 kTransaction Summary===================================================================Install       1 Package(s)Total download size: 222 kInstalled size: 1.1 MIs this ok [y/N]: yDownloading Packages:fio-2.0.13-1.el6.x86_64.rpm                    | 222 kB     00:00     exiting because --downloadonly specified [root@vm49 ~]# ls /var/www/html/repo/fio-2.0.13-1.el6.x86_64.rpm6、repoquery的用法[root@tvm-zabbix ~]# repoquery --plugins --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}' --disablerepo='*' --enablerepo='office,base,repo'  --all --quiet --whatprovides phpphp_|-5.3.3_|-40.el6_6_|-x86_64_|-basephp_|-5.3.3_|-40.el6_6_|-x86_64_|-base7、关于 releasever 的问题有一次从 centos6 升级内核到 oracle uek 的 el6 的过程中,发现这样一个错误:[root@test yum.repos.d]# yum whatprovides redhat-releaseLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilehttp://mirros.test.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"Trying other mirror.Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again这是几个意思?%24releasever通过下述命令可以获得参数 releasever 的值:[root@test yum.repos.d]# rpm -qif /etc/redhat-release[root@test yum.repos.d]# /usr/bin/python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'Loaded plugins: fastestmirror{'arch': 'ia32e', 'basearch': 'x86_64', 'releasever': '6Server', 'uuid': '94e7c860-deb5-4650-a5a6-7064c948f05c'}正常应该是$releasever在 centos6 下,这个值是 6在 el6 下,这个值是 6Server显然,这里有以下几个地方要调整:1)/etc/yum.confdistroverpkg=centos-release变更为:distroverpkg=redhat-release2)/etc/yum.repos.d/xxx.repo这里对应写入 $releasever 这个变量的 URL 都要检查一下 yum 源是否能正常访问。对应上面的实例就是:http://mirros.test.com/centos/%24releasever/os/x86_64/repodata/repomd.xml应该检查:http://mirros.test.com/centos/6Server/os/x86_64/repodata/repomd.xml