【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@office
Release     : 1.el6                         Build Date: Thu 06 Aug 2015 04:53:26 PM CST
Install Date: (not installed)               Build Host: tvm-saltmaster
Group       : default                       Source RPM: office-repo-latest-6-1.el6.src.rpm
Size        : 2392                             License: unknown
Signature   : (none)
Packager    : PC
URL         : http://example.com/no-uri-given
Summary     : provide file: [local-office.repo] for local users. include: centos-base, eple, user-define rpms
Description :
provide file: [local-office.repo] for local users. include: centos-base, eple, user-define rpms

2、安装
yum install lrzsz screen
yum 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 all
yum 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/ fio
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package fio.x86_64 0:2.0.13-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================
 Package        Arch        Version        Repository        Size
===================================================================
Installing:
 fio        x86_64        2.0.13-1.el6        epel        222 k

Transaction Summary
===================================================================
Install       1 Package(s)

Total download size: 222 k
Installed size: 1.1 M
Is this ok [y/N]: y
Downloading 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.rpm



6、repoquery的用法
[root@tvm-zabbix ~]# repoquery --plugins --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}' --disablerepo='*' --enablerepo='office,base,repo'  --all --quiet --whatprovides php
php_|-5.3.3_|-40.el6_6_|-x86_64_|-base
php_|-5.3.3_|-40.el6_6_|-x86_64_|-base



7、关于 releasever 的问题
有一次从 centos6 升级内核到 oracle uek 的 el6 的过程中,发现这样一个错误:
[root@test yum.repos.d]# yum whatprovides redhat-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
http://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.conf
distroverpkg=centos-release
变更为:
distroverpkg=redhat-release


2)/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