Linux程序包管理(二)
说完了程序包管理以及rpm的相关使用,接下来说说rpm的前端管理工具 YUM
YUM是什么?
   前面提到,yum是rpm程序包管理器的前端管理工具,那么yum到底是什么?又能做什么呢? YUM:yellow dog,Yellowdog Update Modifier,是一个在Fedora和RedHat以及CentOS中Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
   yum的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级,安装, 删除等操作,减少了Linux用户一直头痛的dependencies的问题. 这一点上,yum和apt相同. apt原为debian的deb类型软件管理所使用,但是现在也能用到RedHat 门下的rpm了.
  yum主要功能是更方便的添加/删除/更新RPM包,自动解决包的依赖性问题,便于管理大量系统的更新问题.
  yum可以同时配置多个资源库(Repository),简洁的配置文件(/etc/yum.conf),自动解决增加或删除rpm包时遇到的依赖性问题,保持与RPM数据库的一致性.
YUM特点
-
可以同时配置多个资源库
-
简介的配置文件
-
自动解决或增加包的依赖关系
-
保持与RPM数据库的一致性
配置YUM仓库
前面说到,yum可以配置多个资源库(Repository),这里我们根据yum的几个配置文件来分别说明: [root@Daniel ~]# cd /etc/yum.repos.d/ [root@Daniel yum.repos.d]# ls CentOS-Base.repo.bak CentOS-Debuginfo.repo CentOS-Local.repo CentOS-Sources.repo dstat-0.7.2-1.el5.rfx.noarch.rpm CentOS-CR.repoCentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo [root@Daniel yum.repos.d]# cat CentOS-Sources.repo # CentOS-Sources.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base-source] name=CentOS-$releasever - Base Sources baseurl=http://vault.centos.org/centos/$releasever/os/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates-source] name=CentOS-$releasever - Updates Sources baseurl=http://vault.centos.org/centos/$releasever/updates/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras-source] name=CentOS-$releasever - Extras Sources baseurl=http://vault.centos.org/centos/$releasever/extras/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus-source] name=CentOS-$releasever - Plus Sources baseurl=http://vault.centos.org/centos/$releasever/centosplus/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/yum.repos.d/下文件查看
此配置文件为yum默认生效的文件,及执行yum安装程序包时,系统是根据此文件中的说明去查找相关程序包安装
[root@Daniel yum.repos.d]# cat CentOS-Base.repo.bak # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # #
CentOS官方镜像源
[base] name=CentOS-$releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
发行版更新
#released updates [updates] name=CentOS-$releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
额外可用的包
#additional packages that may be useful [extras] name=CentOS-$releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
继承已经存在包功能的包,默认不可用
#additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
我们截取其中相同部分做详细说明:
仓库指向的定义: [repositoryID] 表示“源标识”,可是指明是CentOS 7.x 或者Fedora EPEL源等 name=Some name for this repository 为仓库指定名字 baseurl=url://path/to/repository/ 仓库地址 enabled={1|0} 表示此仓库是否可用,0表示不可用,1表示可用,默认为1 gpgcheck={1|0} 是否进行仓库来源完整性和合法性检测,1表示检测,0表示不检测, gpgkey=URL 指明密钥文件 enablegroups={1|0} 是否允许在此仓库基础上使用 组 批量管理程序包,默认1允许。 failovermethod={roundrobin|priority} 默认为:roundrobin,意为随机挑选; cost= 默认为1000
配置yum源示例:
首先将本地镜像文件挂载好之后进入挂载目录/etc/cdrom/下面查看,有一个Package目录
[root@Daniel yum.repos.d]# cd /media/cdrom/ [root@Daniel cdrom]# ls CentOS_BuildTag EULA imagesLiveOSrepodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL [root@Daniel cdrom]# pwd /media/cdrom
然后配置yum文件
[root@Daniel cdrom]# cd /etc/yum.repos.d/ [root@Daniel yum.repos.d]# cat CentOS-Local.repo [CentOS7.2] 源标识 为 CentOS7.2 name=CentOS 7.2 源名字 为 CentOS7.2 baseurl=file:///media/cdrom 源路径 这里就是镜像的挂载路径 gpgcheck=0 是否检查来源合法性和包完整性,不检查 enabled=1 是否启用此仓库,默认为1 启用,可以不用写 上面为本地源 下面为网源 [Fedora-EPEL] name=Fedora EPEL for EL7 baseurl=http://mirrors.aliyun.com/epel/7/x86_64/ 此网源为阿里云的epel源 gpgcheck=0
清理yum缓存
[root@Daniel cdrom]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源: CentOS7.2 Fedora-EPEL Cleaning up everything Cleaning up list of fastest mirrors [root@Daniel cdrom]# yum repolist 已加载插件:fastestmirror, langpacks CentOS7.2 | 3.6 kB 00:00:00 Fedora-EPEL | 4.3 kB 00:00:00 (1/5): CentOS7.2/group_gz | 155 kB 00:00:00 (2/5): CentOS7.2/primary_db | 5.3 MB 00:00:00 (3/5): Fedora-EPEL/group_gz | 170 kB 00:00:02 (4/5): Fedora-EPEL/updateinfo | 558 kB 00:00:03 (5/5): Fedora-EPEL/primary_db | 4.1 MB 00:00:04 Determining fastest mirrors 源标识源名称 状态 CentOS7.2 CentOS 7.2 9,007 Fedora-EPEL Fedora EPEL for EL710,082 repolist: 19,089 [root@Daniel cdrom]#
可以看到上述源标识名称和状态可用,表名yum源配置成功
YUM安装
rpm -ivh yum-2.0.4-2noarch.rpm
YUM相关命令使用
yum [options] [command] [package ...] command is one of: * install package1 [package2] [...] * update [package1] [package2] [...] * update-to [package1] [package2] [...] * check-update * upgrade [package1] [package2] [...] * upgrade-to [package1] [package2] [...] * distribution-synchronization [package1] [package2] [...] * remove | erase package1 [package2] [...] * list [...] * info [...] * provides | whatprovides feature1 [feature2] [...] * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] * makecache * groupinstall group1 [group2] [...] * groupupdate group1 [group2] [...] * grouplist [hidden] [groupwildcard] [...] * groupremove group1 [group2] [...] * groupinfo group1 [...] * search string1 [string2] [...] * shell [filename] * resolvedep dep1 [dep2] [...] * localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) * localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update) * reinstall package1 [package2] [...] * downgrade package1 [package2] [...] * deplist package1 [package2] [...] * repolist [all|enabled|disabled] * version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ] * history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] * check * help [command]
显示仓库列表:
repolist [all|enabled|disabled] [root@Daniel ~]# yum repolist enabled 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 源标识源名称 状态 CentOS7.2 CentOS 7.2 9,007 Fedora-EPEL Fedora EPEL for EL710,082 repolist: 19,089 [root@Daniel ~]# yum repolist disabled 已加载插件:fastestmirror, langpacks 源标识 源名称 C7.0.1406-base/x86_64CentOS-7.0.1406 - Base C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates C7.1.1503-base/x86_64CentOS-7.1.1503 - Base C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates base-debuginfo/x86_64CentOS-7 - Debuginfo base-source/7CentOS-7 - Base Sources c7-media CentOS-7 - Media centosplus-source/7 CentOS-7 - Plus Sources cr/7/x86_64 CentOS-7 - cr extras-source/7 CentOS-7 - Extras Sources fasttrack/7/x86_64 CentOS-7 - fasttrack updates-source/7 CentOS-7 - Updates Sources repolist: 0 [root@Daniel ~]# yum repolist all 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 源标识 源名称 状态 C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用 C7.0.1406-centosplus/x86_64CentOS-7.0.1406 - CentOSPlus 禁用 C7.0.1406-extras/x86_64CentOS-7.0.1406 - Extras 禁用 C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用 C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用 C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用 C7.1.1503-centosplus/x86_64CentOS-7.1.1503 - CentOSPlus 禁用 C7.1.1503-extras/x86_64CentOS-7.1.1503 - Extras 禁用 C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用 C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用 CentOS7.2 CentOS 7.2 启用: 9,007 Fedora-EPELFedora EPEL for EL7 启用: 10,082 base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用 base-source/7 CentOS-7 - Base Sources 禁用 c7-media CentOS-7 - Media 禁用 centosplus-source/7CentOS-7 - Plus Sources 禁用 cr/7/x86_64CentOS-7 - cr 禁用 extras-source/7CentOS-7 - Extras Sources 禁用 fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用 updates-source/7 CentOS-7 - Updates Sources 禁用 repolist: 19,089 [root@Daniel ~]#
显示程序包:
list # yum list [all | glob_exp1] [glob_exp2] [...] # yum list {available|installed|updates} [glob_exp1] [...]
安装程序包:
install package1 [package2] [...] reinstall package1 [package2] [...] (重新安装) [root@Daniel ~]# yum install unixODBC.x86_64 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 正在解决依赖关系 --> 正在检查事务 ---> 软件包 unixODBC.x86_64.0.2.3.1-11.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================================================== Package 架构 版本 源 大小 ============================================================================================================================================== 正在安装: unixODBC x86_64 2.3.1-11.el7 CentOS7.2 413 k 事务概要 ============================================================================================================================================== 安装 1 软件包 总下载量:413 k 安装大小:1.2 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装: unixODBC-2.3.1-11.el7.x86_64 1/1 验证中 : unixODBC-2.3.1-11.el7.x86_64 1/1 已安装: unixODBC.x86_64 0:2.3.1-11.el7 完毕! [root@Daniel ~]#
升级程序包:
update [package1] [package2] [...] downgrade package1 [package2] [...] (降级)
检查可用升级:
check-update [root@Daniel ~]# yum check-update 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile dstat.noarch 0.7.2-12.el7 CentOS7.2 htop.x86_64 2.0.1-1.el7 Fedora-EPEL libgpod.x86_640.8.3-7.el7 Fedora-EPEL [root@Daniel ~]#
卸载程序包:
remove | erase package1 [package2] [...] [root@Daniel ~]# yum remove unixODBC 已加载插件:fastestmirror, langpacks 正在解决依赖关系 --> 正在检查事务 ---> 软件包 unixODBC.x86_64.0.2.3.1-11.el7 将被 删除 --> 正在处理依赖关系 libesoobS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libmimerS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libnn.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbccr.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbcdrvcfg1S.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbcdrvcfg2S.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbcminiS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbcnnS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libodbctxtS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 liboplodbcS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 liboraodbcS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libsapdbS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libtdsS.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 libtemplate.so.2()(64bit),它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在处理依赖关系 unixODBC(x86-64) = 2.3.1-11.el7,它被软件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 unixODBC-devel.x86_64.0.2.3.1-11.el7 将被 删除 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================== Package 架构 版本源大小 ============================================================================================================== 正在删除: unixODBC x86_64 2.3.1-11.el7@CentOS7.2 1.2 M 为依赖而移除: unixODBC-devel x86_64 2.3.1-11.el7installed186 k 事务概要 ============================================================================================================== 移除 1 软件包 (+1 依赖软件包) 安装大小:1.4 M 是否继续?[y/N]:y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在删除: unixODBC-devel-2.3.1-11.el7.x86_641/2 正在删除: unixODBC-2.3.1-11.el7.x86_64 2/2 验证中 : unixODBC-devel-2.3.1-11.el7.x86_641/2 验证中 : unixODBC-2.3.1-11.el7.x86_64 2/2 删除: unixODBC.x86_64 0:2.3.1-11.el7 作为依赖被删除: unixODBC-devel.x86_64 0:2.3.1-11.el7 完毕!
查看程序包information:
info [...]
查看指定的特性(可以是某文件)是由哪个程序包所提供:
provides | whatprovides feature1 [feature2] [...] [root@Daniel ~]# yum provides /bin/ls 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts 源:CentOS7.2 匹配来源: 文件名:/bin/ls coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts 源:@anaconda 匹配来源: 文件名:/bin/ls
清理本地缓存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] [root@Daniel ~]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源: CentOS7.2 Fedora-EPEL Cleaning up everything Cleaning up list of fastest mirrors
构建缓存:
makecache
搜索:
search string1 [string2] [...] 以指定的关键字搜索程序包名及summary信息;
查看指定包所依赖的capabilities:
deplist package1 [package2] [...]
查看yum事务历史:
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
安装及升级本地程序包:
* localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) * localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update)
包组管理的相关命令:
* groupinstall group1 [group2] [...] * groupupdate group1 [group2] [...] * grouplist [hidden] [groupwildcard] [...] * groupremove group1 [group2] [...] * groupinfo group1 [...]
yum的命令行选项:
--nogpgcheck:禁止进行gpg check; -y: 自动回答为“yes”; -q:静默模式; --disablerepo=repoidglob:临时禁用此处指定的repo; --enablerepo=repoidglob:临时启用此处指定的repo; --noplugins:禁用所有插件;
原创文章,作者:Daniel-W,如若转载,请注明出处:http://www.178linux.com/17243
评论列表(2条)
K8tIU7 http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com
Cob,ii&nlsp;Afrand to say that there was no influence from S.O.A.P. on my novel (though I have subsequently seen the movie). I do, though, much enjoy writing scenes that involve aircraft, as I spent 6 years in the Air Force, many years doing volunteer work with a group called The Commemorative Air Force (CAF) restoring a WW2 B-17 bomber, and have been around aircraft, in one capacity or another, for pretty much all my adult life. This likely shows in the writing where aircraft are involved in some way.234f