首页 > 其他 > 详细

软件包管理之yum

时间:2016-03-20 02:15:34      阅读:322      评论:0      收藏:0      [点我收藏+]

        yum(Yellodog Updater Modified)简介:

             yum是由yello dog开发的并被Red Hat系列发扬光大的一款前端RPM包管理器,其还是依赖于RPM

包而存在,但是却解决了RPM安装时候的各种依赖关系,大大方便了用户。

     yum原理:

       建立一个yum仓库,并在yum配置文件中指定其URL,当用户用yum安装某软件时,yum先连接到指定的仓库,下载器仓库下的对所有软件映射的元数据文件——包含了每个软件的各种信息,例如依赖关系,然后与本地软件数据库文件对比,分析需要安装哪些软件,然后从指定的yum仓库下载需要的所有软件自动安装,安装完成以后自动将所有下载的软件包文件删除,但是元数据文件不删除,这是方便以后

再使用这个指定仓库时候不用下载元数据文件(在repodata下),但是每次使用yum安装软件时候都会

再去请求这个元数据文件的校验码与本地缓存的元数据校验,如果没有发生变化就不重新下载这个元数据文件,如果发生变化了就不用重新下载而是接着使用缓存中的元数据文件。

    yum配置:

       可以通过rpm -qc查询出yum的配置文件。

       [root@bogon ~]# rpm -qc yum
        /etc/logrotate.d/yum
        /etc/yum.conf
        /etc/yum/version-groups.conf

       这里面主要是/etc/yum.conf这是主配置文件,其里面包含了/etc/yum.repos.d/*.repo

       # PUT YOUR REPOS HERE OR IN separate files named file.repo
       # in /etc/yum.repos.d

        虽然文件只是指定了这个目录,但是需要注意的是/etc/repos.d下的文件只有以.repo结尾才

会被yum识别。这样的话就可以在这个目录下自己创建以.repo结尾的配置文件来自己指定yum仓库,系统

自带的yum配置文件如下

      [root@bogon ~]# ls /etc/yum.repos.d
      CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
      CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

如果自己去看看除了第一个仓库以外的其他仓库,会发现都没有启用(enable=0),例如

      [root@bogon ~]# less /etc/yum.repos.d/CentOS-Debuginfo.repo
                     省略、、                
      [base-debuginfo]
      name=CentOS-7 - Debuginfo
      baseurl=http://debuginfo.centos.org/7/$basearch/
      gpgcheck=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
      enabled=0

        仓库配置法则:

         [ID号](不要重复)

          name=可自己随意取名

          baseurl=自己要指定的yum仓库,注意是指定到有repodata的地方!!可以指定多个。

          gpgcheck:合法性检验为0不检验为1检验

          gpgkey=key所在路径,既然要检验那就德告诉yum key的位置啊。

          enable=0或1,0代表不启用这个仓库,为1表达启用,默认就是启用

        这样一个仓库就配置好了,如果需要了解更多的配置man /etc/yum.conf

        这里baseurl可以用mirrorlist替换,就是指定这个mirrorlist的路径,然后yum通过这个路径

找到mirrorlist,这里面配置了baseurl,但是需要插件。

        由于官方发行版光盘可以当一个yum仓库,所以可以直接挂载并配置文件使用。注意先把开启的那个仓库改名,只要不是以.repo结尾就行。不然的话还是会使用这个仓库。

       [root@bogon yum.repos.d]# mount -r /dev/cdrom /media/cdrom/
       [root@bogon yum.repos.d]# ls /media/cdrom/
        CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
        EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
        EULA             isolinux  repodata  TRANS.TBL
      [root@bogon yum.repos.d]# ls
       CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
       CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  local.repo.bak
      [root@bogon yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
      [root@bogon yum.repos.d]# ls
      CentOS-Base.repo.bak  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
      CentOS-CR.repo        CentOS-fasttrack.repo  CentOS-Sources.repo   
      [ yum.repos.d]#vim local.repo  
      1 [base]
      2 name=localrepo
      3 baseurl=file:///media/cdrom
      4 gpgcheck=0      
            注意: baseurl可以是ftp,http,file

        好了,在使用前得先知道yum命令啊,下面来说说yum命令的使用

        刚配置完yum先来查看一下有哪些yum仓库可用,使用

            yum repolist:列出可用仓库

     [root@bogon yum.repos.d]# yum repolist
      Loaded plugins: fastestmirror
      Loading mirror speeds from cached hostfile
      repo id                                 repo name                         status
      base                                    localrepo                          9,007
      repolist: 9,007

           yum list[installed|updates|avaliable|all]:列出仓库所有程序与all一样,已安装程序

可更新程序,可用程序。

                 yum install 软件名(可用接多个):安装

[root@bogon yum.repos.d]# rpm -q zsh
package zsh is not installed
[root@bogon yum.repos.d]# yum install zsh
Loaded plugins: fastestmirror
base                                                             | 3.6 kB  00:00:00     
base/primary_db                                                  | 2.8 MB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-14.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
 Package          Arch                Version                   Repository         Size
========================================================================================
Installing:
 zsh              x86_64              5.0.2-14.el7              base              2.4 M
Transaction Summary
========================================================================================
Install  1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zsh-5.0.2-14.el7.x86_64                                              1/1 
  Verifying  : zsh-5.0.2-14.el7.x86_64                                              1/1
Installed:
  zsh.x86_64 0:5.0.2-14.el7                                                            
Complete!
[root@bogon yum.repos.d]# 
[root@bogon yum.repos.d]# rpm -q zsh
 zsh-5.0.2-14.el7.x86_64

            yum update 程序名:升级

            yum info 程序名:输出指定程序的信息

[root@bogon yum.repos.d]# yum info zsh
Loaded plugins: fastestmirrorL 
oading mirror speeds from cached hostfile
Installed Packages
Name        : zsh
Arch        : x86_64
Version     : 5.0.2
Release     : 14.el7
Size        : 5.6 M
Repo        : installed
From repo   : base
Summary     : Powerful interactive shell
URL         : License     : MIT
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.

            yum  check-update:检查可用升级

            yum  remove 程序名:卸载

[root@bogon yum.repos.d]# yum remove zsh
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-14.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
 Package         Arch               Version                     Repository         Size
========================================================================================
Removing:
 zsh             x86_64             5.0.2-14.el7                @base             5.6 M
Transaction Summary
========================================================================================
Remove  1 Package
Installed size: 5.6 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : zsh-5.0.2-14.el7.x86_64                                              1/1 
  Verifying  : zsh-5.0.2-14.el7.x86_64                                              1/1
Removed:
  zsh.x86_64 0:5.0.2-14.el7                                                            
Complete!
[root@bogon yum.repos.d]# 
[root@bogon yum.repos.d]# rpm -q zsh
package zsh is not installed

            yum provides 程序名:查询哪个程序包提供了这个功能(whatprovides也行)

[root@bogon yum.repos.d]# yum provides zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
zsh-5.0.2-14.el7.x86_64 : Powerful interactive shell
Repo        : base

            yum clean all:手动清理所有缓存,与只对应的构建缓存是yum makecache

            yum search 字符串:以字符串搜索匹配的程序和信息

            yum reinstall 程序名:重新安装

[root@bogon yum.repos.d]# rpm -q zsh
zsh-5.0.2-14.el7.x86_64
[root@bogon yum.repos.d]# yum reinstall zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-14.el7 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
 Package          Arch                Version                   Repository         Size
========================================================================================
Reinstalling:
 zsh              x86_64              5.0.2-14.el7              base              2.4 M
Transaction Summary
========================================================================================
Reinstall  1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: t^Hy^H^H^H
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zsh-5.0.2-14.el7.x86_64                                              1/1 
  Verifying  : zsh-5.0.2-14.el7.x86_64                                              1/1
Installed:
  zsh.x86_64 0:5.0.2-14.el7                                                            
Complete!
[root@bogon yum.repos.d]#

            yum deplist 程序名:列出此程序的依赖程序以及其提供者

[root@bogon yum.repos.d]# yum deplist zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
package: zsh.x86_64 5.0.2-14.el7
  dependency: /bin/sh
   provider: bash.x86_64 4.2.46-19.el7
  dependency: /sbin/install-info
   provider: info.x86_64 5.1-4.el7
  dependency: coreutils
   provider: coreutils.x86_64 8.22-15.el7
  dependency: grep
   provider: grep.x86_64 2.20-2.el7
  dependency: libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libdl.so.2()(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libm.so.6()(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libm.so.6(GLIBC_2.2.5)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libncursesw.so.5()(64bit)
   provider: ncurses-libs.x86_64 5.9-13.20130511.el7
  dependency: librt.so.1()(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: librt.so.1(GLIBC_2.2.5)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libtinfo.so.5()(64bit)
   provider: ncurses-libs.x86_64 5.9-13.20130511.el7
  dependency: rtld(GNU_HASH)
   provider: glibc.x86_64 2.17-105.el7
[root@bogon yum.repos.d]#

            yum history:历史yum事件

[root@bogon yum.repos.d]# yum history
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    38 | reinstall zsh            | 2016-03-19 19:44 | Reinstall      |    1   
    37 | install zsh              | 2016-03-19 19:44 | Install        |    1   
    36 | remove zsh               | 2016-03-19 19:36 | Erase          |    1   
    35 | install zsh              | 2016-03-19 19:30 | Install        |    1   
    34 | install links            | 2016-03-19 15:58 | Install        |    3   
    33 | install wget             | 2016-03-19 15:55 | Install        |    1 P<
    32 | install ftp              | 2016-03-18 11:33 | Install        |    1 > 
    31 | groupremove gnome deskto | 2016-03-18 11:05 | Erase          |  158   
    30 | groupinstall gnome deskt | 2016-03-18 10:56 | Install        |  679   
    29 | install tree             | 2016-03-18 10:54 | Install        |    1   
    28 | groupinstall development | 2016-03-18 10:49 | Install        |   30   
    27 | groupremove Development  | 2016-03-18 10:49 | Erase          |   30   
    26 | groupinstall Development | 2016-03-18 10:48 | Install        |   30   
    25 | remove gcc               | 2016-03-18 10:47 | Erase          |    1   
    24 | reinstall gcc            | 2016-03-18 10:47 | Reinstall      |    1   
    23 | install gcc              | 2016-03-18 10:47 | Install        |    1   
    22 | groupremove Development  | 2016-03-18 10:45 | Erase          |   30   
    21 | groupinstall Development | 2016-03-18 10:44 | Install        |   30   
    20 | groupremove Development  | 2016-03-18 10:44 | Erase          |   30   
    19 | groupinstall Development | 2016-03-18 10:43 | Install        |   30   
history list
[root@bogon yum.repos.d]#

        组管理:

            yum grouplist:列出所有可用包组

[root@bogon yum.repos.d]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Installed Groups:
   Development Tools
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Graphical Administration Tools  
  Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[root@bogon yum.repos.d]#

            yum groupinstall "包组名"

[root@bogon yum.repos.d]# yum groupinstall security tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Warning: group security does not exist.
Warning: group tools does not exist.
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or update
[root@bogon yum.repos.d]# yum groupinstall Security Tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Warning: group Security does not exist.
Warning: group Tools does not exist.
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or update
[root@bogon yum.repos.d]# yum groupinstall "Security Tools"
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package scap-security-guide.noarch 0:0.1.25-3.el7.centos.0.1 will be installed
--> Processing Dependency: openscap-scanner >= 1.2.5 for package: scap-security-guide-0.1.25-3.el7.centos.0.1.noarch
--> Running transaction check
---> Package openscap-scanner.x86_64 0:1.2.5-3.el7 will be installed
--> Processing Dependency: openscap(x86-64) = 1.2.5-3.el7 for package: openscap-scanner-1.2.5-3.el7.x86_64
--> Processing Dependency: libopenscap.so.8()(64bit) for package: openscap-scanner-1.2.5-3.el7.x86_64
--> Running transaction check
---> Package openscap.x86_64 0:1.2.5-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
 Package                   Arch         Version                        Repository  Size
========================================================================================
Installing for group install "Security Tools":
 scap-security-guide       noarch       0.1.25-3.el7.centos.0.1        base       672 k
Installing for dependencies:
 openscap                  x86_64       1.2.5-3.el7                    base       2.9 M
 openscap-scanner          x86_64       1.2.5-3.el7                    base        48 k
Transaction Summary
========================================================================================
Install  1 Package (+2 Dependent packages)
Total download size: 3.6 M
Installed size: 59 M
Is this ok [y/d/N]:   按下y就可以了

            yum groupupdate "包组":更新指定包组

            yum groupremove "包组":卸载指定包组

            yum groupinfo "包组":显示指定包组信息

        yum命令行选项:

            --nogpgcheck:不检查包签名

            -y:自动安装完

            还有别的可以man下相信现在很容易理解了

        下面自行创建yum仓库,这里我将光盘中的程序包都复制到/tmp/pack下,要创建yum仓库其实

就是使用createrepo这个命令来提取每个程序的元数据信息生成repodata目录。

[root@bogon yum.repos.d]# cp -r /media/cdrom/Packages/ /tmp/pack
[root@bogon pack]# createrepo ./
Spawning worker 0 with 1862 pkgs
Spawning worker 1 with 1861 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@bogon pack]# ls | grep "repodata"
repodata

[root@bogon pack]# vim /etc/yum.repos.d/local.repo
   编辑此yum仓库配置文件,当然你也可以自己重新建一个
 1 [base]
  2 name=localrepo
  3 baseurl=file:///tmp/pack
  4 gpgcheck=0
   将baseurl改一下
[root@bogon pack]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                 repo name                                 status
base                                    localrepo                                 3,723
repolist: 3,723 
[root@bogon pack]# yum install zsh
Loaded plugins: fastestmirror
base                                                             | 2.9 kB  00:00:00     
base/primary_db                                                  | 2.8 MB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-14.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
 Package          Arch                Version                   Repository         Size
========================================================================================
Installing:
 zsh              x86_64              5.0.2-14.el7              base              2.4 M
Transaction Summary
========================================================================================
Install  1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zsh-5.0.2-14.el7.x86_64                                              1/1 
  Verifying  : zsh-5.0.2-14.el7.x86_64                                              1/1
Installed:
  zsh.x86_64 0:5.0.2-14.el7                                                            
Complete!
[root@bogon pack]#

        ok!!!

 

 

 

 

 

 

 

 

 

        

 

        

        

       

软件包管理之yum

原文:http://ping520.blog.51cto.com/11282155/1752945

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!