CentOS6.2平台下YUM的配置与使用(转)

  yum是Linux平台(Redhat系列平台)一个软件包管理工具,非常有效地解决包括了安装rpm包时的软件依赖关系。当我们使用rpm(Redhat package Management)在linux下安装rpm软件包时,经常会提示由于安装包的依赖关系而而导致安装失败。使用yum安装工具,将完美地解决rpm包的依赖问题。

  YUM包括两个部分:YUM软件包仓库——存放着RPM软件包,及记录这些RPM软件包的依赖关系的文件(一个XML文件);YUM安装
程序——yum。YUM软件包仓库可以是一个ftp server,一个web server,也可以是本地的某个目录,或者光盘。

  CentOS的安装光盘本自已就是一个YUM仓库。在CentOS安装光盘的根目录下有一个叫做repodata的文件夹,该文件夹中有一个名为repomd.xml的文件,这就是作为一个YUM仓库的标志:

[root@localhost repodata]# pwd
/mnt/cdrom/repodata
[root@localhost repodata]# ls
0575fcbebee20af1f23eb59953ebf17f48093af113ebf32d9fd7225c848900f3-primary.xml.gz
2dd4bee8fd1e52724596e48a02052bdfa61427164057923104d302eef71eacaf-filelists.sqlite.bz2
33ee237c3e507a5d64bbcddb0cace45eaafe95131f33e2cba6dc9c1c84359d4f-other.sqlite.bz2
4444b4332ea3e78db330d6697070a3c7351290d9f1e6d310f59daec4028c78ac-filelists.xml.gz
8709f838a5bbf68868c1a7cbac9fced6a6ea4fd84b68b121a71b642dd7950825-other.xml.gz
9ed11ec7df623b5da32fafaea87ef4e15d4998791845846aa13e81f5a2809005-primary.sqlite.bz2
c87239a7b3d4abd4200826fb9f2d043944a3a3944fd5152154064bdb1dfbd62b-c6-i386-comps.xml.gz
cffddde71947e5fe5a7ce5b77b36decb71afe14b09e3160eba4b4acdd90daa9f-c6-i386-comps.xml.gz
e9226c33fcd943a60c7a631c67895c01e61f4e62577c37e971cfe61de32239ff-c6-i386-comps.xml
repomd.xml
TRANS.TBL

  有了YUM软件仓库后,还得为yum安装工具进行配置,yum安装工具所需要的配置文件一个是/etc/yum.conf,另一个是/etc/yum.repos.d目录下的关于YUM软件仓库的配置文件。/etc/yum.repod.d目录下存储着YUM仓库的配置信息,安装完CentOS 6.2后,/etc/yum.repod.d目录默认有三个配置文件。
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo

  在上面三个配置文件中CentOS-Media.repo就是关于光盘YUM仓库的信息,默认情况下没有启用,配置的光驱挂载点是/media/cdrom,而我常常把光驱挂载到/mnt/cdrom,修改CentOS-Media.repo,内容如下:
[root@localhost yum.repos.d]# cat CentOS-Media.repo
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
#  CentOS-6.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c6-media [command]

# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c6-media [command]

[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom

gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@localhost yum.repos.d]#
  在上面的配置文件中,c6-media是YUM仓库的名字,enabled=1表示启用YUM仓库,baseurl的值是YUM软件仓库的路径,本例中为/mnt/cdrom。

  了解YUM软件仓库及配置好yum工具的配置环境,下面就可以使用yum管理软件包了。

[root@localhost /]# yum --disablerepo=\* --enablerepo=c6-media info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name        : php
Arch        : i686
Version     : 5.3.3
Release     : 3.el6_1.3
Size        : 1.1 M
Repo        : c6-media
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated webpages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module which adds support for the PHP
            : language to Apache HTTP Server.

  yum info package_name用来查看安装的信息,由于系统中配置了三个YUM仓库信息,参数--disablerepo=\* --enablerepo=c6-media  表示只使用名为c6-media的YUM仓库,即CentOS6.2安装光盘。
  yum deplist package_name查看安装包的依赖关系:
[root@localhost /]# yum --disablerepo=\* --enablerepo=c6-media deplist man
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Finding dependencies:
package: man.i686 1.6f-29.el6
  dependency: libc.so.6(GLIBC_2.3)
   provider: glibc.i686 2.12-1.47.el6
  dependency: coreutils
   provider: coreutils.i686 8.4-16.el6
  dependency: libc.so.6(GLIBC_2.1)
   provider: glibc.i686 2.12-1.47.el6
  dependency: rtld(GNU_HASH)
   provider: glibc.i686 2.12-1.47.el6
  dependency: /bin/bash
   provider: bash.i686 4.1.2-8.el6.centos
  dependency: lzma
   provider: xz-lzma-compat.i686 4.999.9-0.3.beta.20091007git.el6
  dependency: less
   provider: less.i686 436-10.el6
  dependency: libc.so.6
   provider: glibc.i686 2.12-1.47.el6
  dependency: groff >= 1.18
   provider: groff.i686 1.18.1.4-21.el6
  dependency: libc.so.6(GLIBC_2.0)
   provider: glibc.i686 2.12-1.47.el6
  dependency: nroff-i18n
   provider: groff.i686 1.18.1.4-21.el6
  dependency: libc.so.6(GLIBC_2.4)
   provider: glibc.i686 2.12-1.47.el6
  dependency: bzip2
   provider: bzip2.i686 1.0.5-7.el6_0
  dependency: findutils
   provider: findutils.i686 1:4.4.2-6.el6
  dependency: gzip
   provider: gzip.i686 1.3.12-18.el6
  dependency: libc.so.6(GLIBC_2.3.4)
   provider: glibc.i686 2.12-1.47.el6
  dependency: rpm
   provider: rpm.i686 4.8.0-19.el6
  dependency: /bin/sh
   provider: bash.i686 4.1.2-8.el6.centos
  dependency: mktemp >= 1.5-2.1.5x
   provider: coreutils.i686 8.4-16.el6

  yum install package_name安装选完的软件包;

[root@localhost /]# yum --disablerepo=\* --enablerepo=c6-media install man
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package man.i686 0:1.6f-29.el6 will be installed
--> Processing Dependency: lzma for package: man-1.6f-29.el6.i686
--> Running transaction check
---> Package xz-lzma-compat.i686 0:4.999.9-0.3.beta.20091007git.el6 will be installed
--> Processing Dependency: xz = 4.999.9-0.3.beta.20091007git.el6 for package: xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686
--> Running transaction check
---> Package xz.i686 0:4.999.9-0.3.beta.20091007git.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
Package                        Arch     Version                              Repository       Size
====================================================================================================
Installing:
man                            i686     1.6f-29.el6                          c6-media        260 k
Installing for dependencies:
xz                             i686     4.999.9-0.3.beta.20091007git.el6     c6-media        137 k
xz-lzma-compat                 i686     4.999.9-0.3.beta.20091007git.el6     c6-media         16 k

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

Total download size: 412 k
Installed size: 864 k
Is this ok [y/N]: y
Downloading Packages:
-------------------------------------------------------------------------------------------------------------------------------
Total                                                                                          831 kB/s | 412 kB     00:00    
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>
Package: centos-release-6-2.el6.centos.7.i686 (@anaconda-CentOS-201112130233.i386/6.2)
From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : xz-4.999.9-0.3.beta.20091007git.el6.i686                                                                    1/3
  Installing : xz-lzma-compat-4.999.9-0.3.beta.20091007git.el6.i686                                                        2/3
  Installing : man-1.6f-29.el6.i686                                                                                        3/3

Installed:
  man.i686 0:1.6f-29.el6                                                                                                      

Dependency Installed:
  xz.i686 0:4.999.9-0.3.beta.20091007git.el6            xz-lzma-compat.i686 0:4.999.9-0.3.beta.20091007git.el6                            

Complete!
[root@localhost /]#

yum -y install package_name中的-y选项会在安装过程中自动确认而不需要管理员再输入y进行手工确认。

[root@localhost ssh]# yum -y --disablerepo=\* --enablerepo=c6-media install tcpdump
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tcpdump.i686 14:4.0.0-3.20090921gitdf3cb4.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
Package                 Arch      Version                                Repository       Size
================================================================================================
Installing:
tcpdump                 i686      14:4.0.0-3.20090921gitdf3cb4.1.el6     c6-media        330 k

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

Total download size: 330 k
Installed size: 759 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 14:tcpdump-4.0.0-3.20090921gitdf3cb4.1.el6.i686                                                                                           1/1

Installed:
  tcpdump.i686 14:4.0.0-3.20090921gitdf3cb4.1.el6                                                                                                           


Complete!

猜你喜欢

转载自liyf155.iteye.com/blog/1528750
今日推荐