上一篇我們介紹了關於使用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! #安裝成功
未完,待續...