yum——替你排忧解难的前端包安装工具

yum

CentOS前端工具: yum, dnf

统一资源定位符:URL

YUM: Yellowdog Update Modifier,rpm的前端程序,用来解决软件包相关依赖性,可以在多个库之间定位软件包,自动安装软件包,以及该软件包的依赖包,up2date的替代工具

yum repository: yum repo (yum仓库)

         存储了众多rpm 包,以及包的相关的元数据文件(放置于特定目录repodata下)

        

         文件服务器:

         ftp://

         http://

         file:///

yum客户端配置文件:

/etc/yum.conf:为所有仓库提供公共配置

/etc/yum.repos.d/*.repo:为仓库的指向提供配置

仓库定义:(/etc/yum.repos.d/*.repo里的配置文件)

         [repositoryID]

         name=Some name for this repository //仓库文字,默认可以不写

         baseurl=url://path/to/repository/   //仓库的位置,必须填写的内容

         enabled={1|0} //是否启用该仓库,0:不启用,1:启用,默认为1(不写),为启用状态

         gpgcheck={1|0}   //是否开启包完整性检查,0:不开启,1:开启,默认为1(不写),为开启包检测状态

         gpgkey=URL //包完整性检测的包路径,若gpgcheck为0,可以不填写此项

         enablegroups={1|0}

         failovermethod={roundrobin|priority}   //仓库被使用的次序,默认是随机,priority按优先级

                 默认为:roundrobin ,意为随机挑选;

         cost=   //仓库开销,值越小,优先级越高

                 默认为1000

eg:CentOS6系统的yum配置

[root@CentOS6 ~]# cat /etc/yum.repos.d/centos6-service.repo
[base]
name=CentOS6 service repo
baseurl=http://10.1.0.1/cobbler/ks_mirror/6/
gpgcheck=0

yum命令的用法:

yum [options] [command] [package …]

[package …]:直接使用包名,而不是包文件名。(注意区别:rpm的安装,是使用包文件名,rpm查询是使用的包名)

[options]

            -y:自动回答为“yes”

            -q:静默模式

            –nogpgcheck:禁止进行gpgcheck

            –disablerepo=repoidglob:临时禁用此处指定的repo

            –enablerepo=repoidglob:临时启用此处指定的repo

            –noplugins:禁用所有插件

command is one of:

       * repolist [all|enabled|disabled]

        显示仓库列表

[root@CentOS6 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
base                                                                                                    | 4.0 kB     00:00     
repo id                                               repo name                                                          status
base                                                  CentOS6 service repo                                               6,696
repolist: 6,696

       * list […]

        显示程序包

        yum list [all|glob_exp|…]

        yum list [available|installed|updates]

[root@CentOS6 ~]# yum list | less
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
ConsoleKit.x86_64                        0.4.1-6.el6                       @anaconda-CentOS-201605220104.x86_64/6.8
ConsoleKit-libs.x86_64                   0.4.1-6.el6                       @anaconda-CentOS-201605220104.x86_64/6.8
ConsoleKit-x11.x86_64                    0.4.1-6.el6                       @anaconda-CentOS-201605220104.x86_64/6.8
DeviceKit-power.x86_64                   014-3.el6                         @anaconda-CentOS-201605220104.x86_64/6.8
GConf2.x86_64                            2.28.0-6.el6                      @anaconda-CentOS-201605220104.x86_64/6.8
GConf2-gtk.x86_64                        2.28.0-6.el6                      @anaconda-CentOS-201605220104.x86_64/6.8
MAKEDEV.x86_64                           3.24-6.el6                        @anaconda-CentOS-201605220104.x86_64/6.8
ModemManager.x86_64                      0.4.0-5.git20100628.el6           @anaconda-CentOS-201605220104.x86_64/6.8

       * install package1 [package2] […]

        安装程序包

       * reinstall package1 [package2] […]

        重新安装程序包

       * update [package1] [package2] […]

        升级程序包

       * downgrade package1 [package2] […]

        降级安装

[root@CentOS6 ~]# yum install zsh
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
 Package                 Arch                       Version                                     Repository                Size
===============================================================================================================================
Installing:
 zsh                     x86_64                     4.3.11-4.el6.centos.2                       base                     2.2 M
Transaction Summary
===============================================================================================================================
Install       1 Package(s)
Total download size: 2.2 M
Installed size: 5.1 M
Is this ok [y/N]:      <--------此处回答y即可安装程序包

       * check-update

        检测可用升级

[root@CentOS6 ~]# yum check-update
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
acpid.x86_64                                            2.0.19-2.0.1.el6.centos.alt                                  xen4centos
kernel.x86_64                                           3.18.12-11.el6                                               xen4centos
kernel-firmware.noarch                                  3.18.12-11.el6                                               xen4centos
kernel-headers.x86_64                                   3.18.12-11.el6                                               xen4centos

       * remove | erase package1 [package2] […]

        卸载程序包

[root@CentOS6 ~]# yum remove tree
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-3.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
 Package                    Arch                         Version                             Repository                   Size
===============================================================================================================================
Removing:
 tree                       x86_64                       1.5.3-3.el6                         @base                        65 k
Transaction Summary
===============================================================================================================================
Remove        1 Package(s)
Installed size: 65 k
Is this ok [y/N]:<--------此处回答y即可卸载程序包

       * info […]

        查看程序包information

[root@CentOS6 ~]# yum info tree
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name        : tree
Arch        : x86_64
Version     : 1.5.3
Release     : 3.el6
Size        : 65 k
Repo        : installed
From repo   : base
Summary     : File system tree viewer
URL         : http://mama.indstate.edu/users/ice/tree/
License     : GPLv2+
Description : The tree utility recursively displays the contents of directories in a
            : tree-like format.  Tree is basically a UNIX port of the DOS tree
            : utility.

       * provides | whatprovides feature1 [feature2] […]

        查看指定的特性(可以是某文件)是由那个程序包提供

[root@CentOS6 ~]# yum provides /etc/fstab
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files
Repo        : base
Matched from:
Filename    : /etc/fstab
setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files
Repo        : installed
Matched from:
Other       : Provides-match: /etc/fstab

       * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

        清除本地缓存

       * makecache

        构建缓存

[root@CentOS6 ~]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@CentOS6 ~]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base                                                                                                    | 4.0 kB     00:00     
base/group_gz                                                                                           | 226 kB     00:00     
base/filelists_db                                                                                       | 6.3 MB     00:00     
base/primary_db                                                                                         | 4.7 MB     00:00     
base/other_db                                                                                           | 2.8 MB     00:00     
Metadata Cache Created

       * search string1 [string2] […]

        以指定的关键字搜素程序包及summary信息

       * deplist package1 [package2] […]

        查看指定包所依赖的capabilities

       * history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]

        查看yum事务历史

                     yum history info 6

                     查看事务历史第6条的详细信息

                     yum history undo 6

                     撤销事务历史第6条的操作,卸载的撤销就是安装,安装的撤销就是卸载

[root@CentOS6 ~]# yum history
Loaded plugins: fastestmirror, refresh-packagekit, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     5 | root <root>              | 2016-08-21 08:17 | Install        |    1   
     4 | root <root>              | 2016-08-21 01:04 | Install        |   25   
     3 | root <root>              | 2016-08-21 00:46 | Install        |   46   
     2 | root <root>              | 2016-08-20 23:24 | Install        |    1   
     1 | System <unset>           | 2016-08-20 22:01 | Install        | 1123   
history list
[root@CentOS6 ~]# yum history info 5
Loaded plugins: fastestmirror, refresh-packagekit, security
Transaction ID : 5
Begin time     : Sun Aug 21 08:17:40 2016
Begin rpmdb    : 1195:acc15ce6b2a873ade9434d29bdca2e6c6a9f5fa4
End time       :            08:17:43 2016 (3 seconds)
End rpmdb      : 1196:83eaa621cb52947d60d21e648bb8f7a7d925156c
User           : root <root>
Return-Code    : Success
Command Line   : install -y tree
Transaction performed with:
    Installed     rpm-4.8.0-55.el6.x86_64                       @anaconda-CentOS-201605220104.x86_64/6.8
    Installed     yum-3.2.29-73.el6.centos.noarch               @anaconda-CentOS-201605220104.x86_64/6.8
    Installed     yum-plugin-fastestmirror-1.1.30-37.el6.noarch @anaconda-CentOS-201605220104.x86_64/6.8
Packages Altered:
    Install tree-1.5.3-3.el6.x86_64 @base
history info

       * localinstall rpmfile1 [rpmfile2] […]

          (maintained for legacy reasons only – use install)

          老版本的安装及升级本地rpm包命令,现在可以直接使用install进行安装

       * localupdate rpmfile1 [rpmfile2] […]

          (maintained for legacy reasons only – use update)

          老版本的安装及升级本地rpm包命令,现在可以直接使用update进行升级

       * help [command]

        查看帮助

       * grouplist [hidden] [groupwildcard] […]

        显示包组(hidden:显示隐藏的包组)

       * groupinstall group1 [group2] […]

        安装包组

       * groupupdate group1 [group2] […]

        更新包组

       * groupremove group1 [group2] […]

        移除包组

       * groupinfo group1 […]

        包组信息

如何使用光盘当作本地yum 仓库:

(1)  挂载光盘至某目录,例如/media/cdrom

        # mount /dev/cdrom /media/cdrom

(2)  创建配置文件

         [CentOS6]

         name=

         baseurl=

         gpgcheck=

eg:光盘yum仓库

    [root@CentOS6 ~]# cat /etc/yum.repos.d/centos6-cdrom.repo
    [cdrom]
    name=CentOS6 cdrom repo
    baseurl=file:///media/cdrom/
    gpgcheck=0

yum的repo配置文件中可用的变量:

$releasever:当前OS的发行版的主版本号

$arch:平台,i386,i486,i586,x86_64等 等

$basearch:基础平台;i386

$YUM0-$YUM9:自定义变量

eg:http://mirrors.gaomengedu.com/centos/$releaserver/$basearch

      http://server/centos/$releasever/$basearch/

     http://server/centos/7/x86_64

     http://server/centos/6/i384

如何创建yum仓库

(1)把网上/其他的rpm包下载到某一路径下

(2)安装createrepo包(安装了此包的可以跳过此步)

(3)进入下载的rpm包的路径下

(4)createrepo ./

     把rpm包的repodate目录文件创建在此目录下

     –basedir  设置repodate目录的路径,默认在当前工作路径

[root@CentOS6 xen]# pwd
/testdir/xen
[root@CentOS6 xen]# ls | wc
     41      41    1498
[root@CentOS6 xen]# createrepo ./
Spawning worker 0 with 41 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@CentOS6 xen]# ls | wc   
     42      42    1507
[root@CentOS6 xen]# ll | grep repo
drwxr-xr-x. 2 root root     4096 Aug 21 08:28 repodata

原创文章,作者:megedugao,如若转载,请注明出处:http://www.178linux.com/39228

(0)
megedugaomegedugao
上一篇 2016-08-24 10:12
下一篇 2016-08-24 10:12

相关推荐

  • 马哥教育网络班22期第五周课程练习1

    1、cat /etc/passwd  | egrep "^root|^fedora|^user1"| cut -d":" -f1,7  2、egrep -o  "[^[:space:]]+\(\)" /etc/rc.d/init.d/functions   3…

    Linux干货 2016-09-15
  • 使用 nice、cpulimit 和 cgroups 限制 cpu 占用率

    Linux内核是一名了不起的马戏表演者,它在进程和系统资源间小心地玩着杂耍,并保持系统的正常运转。 同时,内核也很公正:它将资源公平地分配给各个进程。 但是,如果你需要给一个重要进程提高优先级时,该怎么做呢? 或者是,如何降低一个进程的优先级? 又或者,如何限制一组进程所使用的资源呢? 答案是需要由用户来为内核指定进程的优先级 大部分进程启动时的优先级是相同…

    Linux干货 2015-02-14
  • TCP常见问题总结

    TCP协议和UDP协议的区别是什么 TCP协议是有连接的,有连接的意思是开始传输实际数据之前TCP的客户端和服务器端必须通过三次握手建立连接,会话结束之后也要结束连接。而UDP是无连接的 TCP协议保证数据按序发送,按序到达,提供超时重传来保证可靠性,但是UDP不保证按序到达,甚至不保证到达,只是努力交付,即便是按序发送的序列,也不保证按序送到。 TCP协议…

    Linux干货 2017-09-02
  • Bash shell 脚本编程全攻略(上篇)

    Bash shell 脚本编程全攻略(上篇)   什么是shell脚本呢? 当命令不在命令行上执行,而是通过一个文件执行时,该文件就称为shell脚本,脚本以非交互的方式运行。Shell脚本把命令通过一些语法组织起来,便能实现特定的功能。   Shell脚本主要运用在系统运维中,主要功能有: 自动化常用命令; 执行系统管理和故障排除; 创…

    Linux干货 2016-08-29
  • 马哥Linux学习之查询篇(命令查询和文件查询)

        Linux运维工作一般都使用命令完成,在如此多的各种命令中,要想全部记住显然是不太可能也是不必要的,另外,文件的查找在日常操作中也是必不可少的。下面我就总结一下Linux中如何查找命令以及文件。     命令的运行文件路径查询。这个查找的方法是同样是使用命令,这个命令叫w…

    Linux干货 2015-04-13
  • Shell编程(1)

    Shell编程:     编程语言:机器语言、汇编语言、高级语言         高级语言:             静…

    Linux干货 2016-08-18