上一篇我们介绍了关于使用rpm对软件包进行管理,我们感觉到,软件包之间的依赖关系使得rpm不那么的方便,今天我们介绍rpm的前端工具yum,yum的出现使得软件包的管理更为方便快捷。
简单说,要想使用yum,必须有一个可用的yum repository,而且客户端需要配置一个有效的yum repo。yum repostory可以通过ftp,http及本地实现,而且,需要使用createrepo生成元数据;之后在客户端配置yum repo的配置文件即可。使用createrepo创建yum仓库,会生成一个repodata的目录,repodata所在的目录就是访问yum仓库的路径(例:ftp://192.168.1.1/source , http://192.168.1.1/source , file:///media/cdrom )。
客户端yum repo的配置文件位置:
/etc/yum.conf #主配置文件
/etc/yum.repo.d/*.repo
[root@wsh ~]# cat /etc/yum.conf [main] #为每一个仓库提供默认配置,通常只有1个(除了[main],每一个[repository_ID]都是一个仓库的定义) cachedir=/var/cache/yum/$basearch/$releasever #缓存目录 keepcache=0 #通过yum将rpm包下载至本地才能安装,下载之后要不要长久保存? debuglevel=2 #调试级别 logfile=/var/log/yum.log #日志文件 exactarch=1 obsoletes=1 gpgcheck=1 #是否自动执行来源合法性检测,1检测,0不检测 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
1.使用本地yum源,及有关yum repo的相关命令:
其实,redhat的安装光盘就是一个yum源,可以直接使用:
[root@wsh ~]# mount /dev/cdrom /media/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@wsh ~]# cd /media/cdrom/ [root@wsh cdrom]# ls #这里有repodata,所以pwd显示的就是访问本地yum源的路径:file:///media/cdrom CentOS_BuildTag GPL RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6 isolinux EFI Packages RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL repodata EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 images
我们在客户端新建一个yum源路径指向本地的.repo配置文件:
[root@wsh cdrom]# vim /etc/yum.repos.d/local.repo [cdrom] #yum仓库的名称,具有唯一性 name=CentOS 6.5 localrepo #简单的描述即可 baseurl=file:///media/cdrom #本地yum源路径使用file://+yum源的绝对路径 gpgcheck=0 #不检查合法性 enabled=1 #是否启用此yum源,没有此项默认启用
yum会将yum仓库中的一些元数据等缓存到本地,我们可以手动清理缓存,也可以手动创建缓存,相关命令:
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
一般常用yum clean metadata
yum makecache,手动创建缓存
[root@wsh cdrom]# yum clean all #在此,全部清理 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: base cdrom extras updates Cleaning up Everything Cleaning up list of fastest mirrors [root@wsh cdrom]# yum makecache #手动创建缓存 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors # 下面是我们新建的名为"cdrom"的yum源(为了显示清晰,我把其余的源删除了) ............... cdrom | 4.0 kB 00:00 ... cdrom/filelists_db | 5.8 MB 00:00 ... cdrom/primary_db | 4.5 MB 00:00 ... cdrom/other_db | 2.6 MB 00:00 ... cdrom/group_gz | 212 kB 00:00 ... ................. Metadata Cache Created
查看客户端配置了哪些yum源:yum repolist [ enabled | disabled | all ]
[root@wsh cdrom]# yum repolist #相当于enabled,即启用的yum源 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile repo id repo name status base CentOS-6 - Base - 163.com 6367 cdrom CentOS 6.5 localrepo 6346 extras CentOS-6 - Extras - 163.com 14 updates CentOS-6 - Updates - 163.com 932 repolist: 13659
[root@wsh cdrom]# yum repolist disabled #没有启用的yum源 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security repo id repo name centosplus CentOS-6 - Plus - 163.com contrib CentOS-6 - Contrib - 163.com repolist: 0 [root@wsh cdrom]# yum repolist all #全部yum源,包括enabled和disabled Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile repo id repo name status base CentOS-6 - Base - 163.com enabled: 6367 cdrom CentOS 6.5 localrepo enabled: 6346 centosplus CentOS-6 - Plus - 163.com disabled contrib CentOS-6 - Contrib - 163.com disabled extras CentOS-6 - Extras - 163.com enabled: 14 updates CentOS-6 - Updates - 163.com enabled: 932 repolist: 13659
2.使用yum安装程序包
yum install name.....
yum reinstall name.....
yum localinstall name-version.release.arch.rpm
由下图可以看出,使用yum非常好的解决了软件之间的依赖关系。
最后完成安装!
[root@wsh cdrom]# yum list | grep "bind" #yum list查看所有已经软件包 Failed to set locale, defaulting to C bind.x86_64 32:9.8.2-0.23.rc1.el6_5.1 @updates bind-libs.x86_64 32:9.8.2-0.23.rc1.el6_5.1 @updates
reinstall的功能:
[root@wsh cdrom]# yum install bind #提示已经安装bind Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Package 32:bind-9.8.2-0.23.rc1.el6_5.1.x86_64 already installed and latest version Nothing to do [root@wsh cdrom]# yum reinstall bind #reinstall实现再次安装bind Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Reinstall Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.8.2-0.23.rc1.el6_5.1 will be reinstalled --> Finished Dependency Resolution Dependencies Resolved
localinstall:使用yum安装本地rpm包,RHEL5使用,6以上使用install即可:
[root@wsh Packages]# yum -y install zsh-4.3.10-5.el6.x86_64.rpm #-y自动回答为yes;如果有依赖关系yum也会一并解决 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Examining zsh-4.3.10-5.el6.x86_64.rpm: zsh-4.3.10-5.el6.x86_64 Marking zsh-4.3.10-5.el6.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package zsh.x86_64 0:4.3.10-5.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ...... ...... Total size: 4.8 M Installed size: 4.8 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : zsh-4.3.10-5.el6.x86_64 1/1 Verifying : zsh-4.3.10-5.el6.x86_64 1/1 Installed: zsh.x86_64 0:4.3.10-5.el6 Complete!
3.升级
yum check-update:检测哪些包需要升级
yum update name:升级
yum update-to name:升级到哪个版本
4.查询
yum info name
yum list [ all | installed | available ] [glob],支持globbing
[root@wsh Packages]# yum info zsh #查询zsh的相关信息,以安装的和未安装的(可以) Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Installed Packages Name : zsh Arch : x86_64 Version : 4.3.10 Release : 5.el6 Size : 4.8 M Repo : installed From repo : /zsh-4.3.10-5.el6.x86_64 Summary : A powerful interactive shell URL : http://zsh.sunsite.dk/ License : BSD Description : The zsh shell is a command interpreter usable as an interactive login : shell and as a shell script command processor. Zsh resembles the ksh : shell (the Korn shell), but includes many enhancements. Zsh supports : command line editing, built-in spelling correction, programmable : command completion, shell functions (with autoloading), a history : mechanism, and more. Available Packages Name : zsh Arch : x86_64 Version : 4.3.10 Release : 7.el6 Size : 2.1 M Repo : base Summary : A powerful interactive shell URL : http://zsh.sunsite.dk/ License : BSD Description : The zsh shell is a command interpreter usable as an interactive login : shell and as a shell script command processor. Zsh resembles the ksh : shell (the Korn shell), but includes many enhancements. Zsh supports : command line editing, built-in spelling correction, programmable : command completion, shell functions (with autoloading), a history : mechanism, and more.
5.卸载
yum remove name
[root@wsh Packages]# yum remove zsh Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package zsh.x86_64 0:4.3.10-5.el6 will be erased --> Finished Dependency Resolution Dependencies Resolved ............. .............. Installed size: 4.8 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Erasing : zsh-4.3.10-5.el6.x86_64 1/1 Verifying : zsh-4.3.10-5.el6.x86_64 1/1 Removed: zsh.x86_64 0:4.3.10-5.el6 Complete!
[root@wsh Packages]# rpm -q zsh
package zsh is not installed
6.模糊查找search:
root@wsh Packages]# yum search zs #查找包含zs的包 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile ====================================================== N/S Matched: zs ====================================================== python-twisted-core-zsh.x86_64 : Tab completion for Zsh and Twisted Core zsh-html.x86_64 : Zsh shell manual in html format lrzsz.x86_64 : The lrz and lsz modem communications programs zsh.x86_64 : A powerful interactive shell Name and summary matches only, use "search all" for everything.
7.hisroty:
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] [root@wsh Packages]# yum history info #查看一些历史操作记录 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Transaction ID : 10 Begin time : Fri May 23 16:41:47 2014 Begin rpmdb : 1106:4fc5bbbfcb8a22d995dbe8709b67a7bf7c261344 End time : 16:41:48 2014 (1 seconds) End rpmdb : 1105:81895fc1e7e74a77f42f5f02564823ec58ccead1 ** User : Root,bycx,110,888 <root> Return-Code : Success Command Line : remove zsh Transaction performed with: Installed rpm-4.8.0-37.el6.x86_64 @anaconda-CentOS-201311272149.x86_64/6.5 Installed yum-3.2.29-40.el6.centos.noarch @anaconda-CentOS-201311272149.x86_64/6.5 Installed yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201311272149.x86_64/6.5 Packages Altered: Erase zsh-4.3.10-5.el6.x86_64 @/zsh-4.3.10-5.el6.x86_64 history info
8.有关包组:
包组,顾名思义,包含了众多软件包。
查看包组:
yum grouplist
[root@wsh ~]# yum grouplist Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile Installed Groups: Additional Development Console internet tools Debugging Tools Desktop .... Installed Language Groups: Arabic Support [ar] Armenian Support [hy] Assamese Support [as] Bengali Support [bn] Bhutanese Support [dz] Chinese Support [zh] ..... Available Groups: Backup Client Backup Server Base Desktop Platform Development Development tools Server Platform Development ......... Available Language Groups: Afrikaans Support [af] Albanian Support [sq] Amazigh Support [ber] Azerbaijani Support [az] Basque Support [eu] .... Done
查看包组包含哪些包:
yum groupinfo group_name
[root@wsh ~]# yum groupinfo "Development tools" Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Group Process Loading mirror speeds from cached hostfile Group: Development tools Description: A basic development environment. Mandatory Packages: autoconf automake binutils bison flex gcc gcc-c++ gettext libtool make patch pkgconfig redhat-rpm-config rpm-build Default Packages: byacc cscope ctags cvs diffstat doxygen elfutils gcc-gfortran git indent intltool patchutils rcs subversion swig systemtap Optional Packages: ElectricFence ant babel bzr chrpath cmake compat-gcc-34 compat-gcc-34-c++ compat-gcc-34-g77 cvs-inetd dejagnu expect gcc-gnat gcc-java gcc-objc gcc-objc++ imake jpackage-utils kdewebdev ksc libstdc++-docs mercurial mod_dav_svn nasm perltidy python-docs rpmdevtools rpmlint systemtap-sdt-devel systemtap-server
安装包组:
yum groupinstall " 包组名 " ......
#Desktop Platform Development #Development tools #Server Platform Development #这3个是RHEL6重要的开发组的包组,下面安装这3个包组 [root@wsh ~]#yum -y groupinstall "Desktop Platform Development" "Development tools" "Server Platform Development" #单个包组名如果有空格需要引号,包组之间空格隔开 #之后就是漫长的等待......
升级包组:
yum groupupdate 包组名
卸载包组:
yum groupremove 包组名
9.客户端配置网络上的yum源:
[root@wsh ~]# vim /etc/yum.repos.d/CentOS6-Base-163.repo #说明:$releasever,代表系统的release号 # $basearch,如果$arch=i686,$basearch=i386;$basearch=x86_64 [base] name=CentOS-$releasever - Base - 163.com baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ gpgcheck=1 enabled=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
10.创建yum仓库:
createrepo dirname
[root@wsh /]# ls /xen/ bridge-utils-1.5-2.el6.x86_64.rpm xen-devel-4.1.2-6.el6.x86_64.rpm bridge-utils-debuginfo-1.5-2.el6.x86_64.rpm xen-doc-4.1.2-6.el6.x86_64.rpm kernel-xen-2.6.32.57-1.x86_64.rpm xen-hypervisor-4.1.2-6.el6.x86_64.rpm kernel-xen-devel-2.6.32.57-1.x86_64.rpm xen-libs-4.1.2-6.el6.x86_64.rpm kernel-xen-firmware-2.6.32.57-1.x86_64.rpm xen-licenses-4.1.2-6.el6.x86_64.rpm kernel-xen-headers-2.6.32.57-1.x86_64.rpm xen-ocaml-4.1.2-6.el6.x86_64.rpm kernel-xen-release-6-3.noarch.rpm xen-ocaml-devel-4.1.2-6.el6.x86_64.rpm xen-4.1.2-6.el6.x86_64.rpm xen-runtime-4.1.2-6.el6.x86_64.rpm xen-debuginfo-4.1.2-6.el6.x86_64.rpm yum-plugin-fastestmirror-1.1.30-10.el6.noarch.rpm [root@wsh /]# createrepo /xen/ #创建yum仓库 18/18 - kernel-xen-headers-2.6.32.57-1.x86_64.rpm Saving Primary metadata Saving file lists metadata Saving other metadata [root@wsh yum.repos.d]# ls /xen/ #生成了repodata bridge-utils-1.5-2.el6.x86_64.rpm xen-devel-4.1.2-6.el6.x86_64.rpm bridge-utils-debuginfo-1.5-2.el6.x86_64.rpm xen-doc-4.1.2-6.el6.x86_64.rpm kernel-xen-2.6.32.57-1.x86_64.rpm xen-hypervisor-4.1.2-6.el6.x86_64.rpm kernel-xen-devel-2.6.32.57-1.x86_64.rpm xen-libs-4.1.2-6.el6.x86_64.rpm kernel-xen-firmware-2.6.32.57-1.x86_64.rpm xen-licenses-4.1.2-6.el6.x86_64.rpm kernel-xen-headers-2.6.32.57-1.x86_64.rpm xen-ocaml-4.1.2-6.el6.x86_64.rpm kernel-xen-release-6-3.noarch.rpm xen-ocaml-devel-4.1.2-6.el6.x86_64.rpm repodata xen-runtime-4.1.2-6.el6.x86_64.rpm xen-4.1.2-6.el6.x86_64.rpm yum-plugin-fastestmirror-1.1.30-10.el6.noarch.rpm xen-debuginfo-4.1.2-6.el6.x86_64.rpm [root@wsh yum.repos.d]# vim xen.repo [xen] name=CentOS XEN baseurl=file:///xen gpgcheck=0 enabled=1 [root@wsh yum.repos.d]# yum clean all Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: xen Cleaning up Everything Cleaning up list of fastest mirrors [root@wsh yum.repos.d]# yum makecache Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors xen | 1.3 kB 00:00 ... xen/filelists | 85 kB 00:00 ... xen/primary | 6.5 kB 00:00 ... xen/other | 6.7 kB 00:00 ... xen 18/18 xen 18/18 xen 18/18 Metadata Cache Created [root@wsh yum.repos.d]# yum repolist enabled #成功配置本地名为xen的yum源 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile repo id repo name status xen CentOS XEN 18 repolist: 18 [root@wsh yum.repos.d]# yum install xen #yum 安装xen Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package xen.x86_64 0:4.1.2-20.el6 will be installed --> Processing Dependency: xen-runtime = 4.1.2-20.el6 for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libxenstore.so.3.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libxenlight.so.1.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libxenguest.so.4.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libxenctrl.so.4.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libflask.so.1.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Processing Dependency: libblktapctl.so.1.0()(64bit) for package: xen-4.1.2-20.el6.x86_64 --> Running transaction check ---> Package xen-libs.x86_64 0:4.1.2-20.el6 will be installed --> Processing Dependency: xen-licenses for package: xen-libs-4.1.2-20.el6.x86_64 ---> Package xen-runtime.x86_64 0:4.1.2-20.el6 will be installed --> Processing Dependency: xen-hypervisor-abi = 4.1 for package: xen-runtime-4.1.2-20.el6.x86_64 --> Running transaction check ---> Package xen-hypervisor.x86_64 0:4.1.2-20.el6 will be installed ---> Package xen-licenses.x86_64 0:4.1.2-20.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================== Installing: xen x86_64 4.1.2-20.el6 xen #通过xen yum源安装1.1 M Installing for dependencies: xen-hypervisor x86_64 4.1.2-20.el6 xen 3.9 M xen-libs x86_64 4.1.2-20.el6 xen 313 k xen-licenses x86_64 4.1.2-20.el6 xen 67 k xen-runtime x86_64 4.1.2-20.el6 xen 4.9 M Transaction Summary ===================================================================================================================================== Install 5 Package(s) Total download size: 10 M Installed size: 26 M Is this ok [y/N]: y Downloading Packages: ------------------------------------------------------------------------------------------------------------------------------------- Total 38 MB/s | 10 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : xen-licenses-4.1.2-20.el6.x86_64 1/5 Installing : xen-libs-4.1.2-20.el6.x86_64 2/5 Installing : xen-hypervisor-4.1.2-20.el6.x86_64 3/5 Installing : xen-runtime-4.1.2-20.el6.x86_64 4/5 Installing : xen-4.1.2-20.el6.x86_64 5/5 Verifying : xen-licenses-4.1.2-20.el6.x86_64 1/5 Verifying : xen-libs-4.1.2-20.el6.x86_64 2/5 Verifying : xen-4.1.2-20.el6.x86_64 3/5 Verifying : xen-hypervisor-4.1.2-20.el6.x86_64 4/5 Verifying : xen-runtime-4.1.2-20.el6.x86_64 5/5 Installed: xen.x86_64 0:4.1.2-20.el6 Dependency Installed: xen-hypervisor.x86_64 0:4.1.2-20.el6 xen-libs.x86_64 0:4.1.2-20.el6 xen-licenses.x86_64 0:4.1.2-20.el6 xen-runtime.x86_64 0:4.1.2-20.el6 Complete! #安装成功
未完,待续...