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
下一篇 2016-08-24

相关推荐

  • 马哥教育网络21期+第六周练习博客

    马哥教育网络21期+第六周练习博客 请详细总结vim编辑器的使用并完成以下练习题     VIM编辑器:         vi:Visual Interface 文本编辑器    &nbsp…

    Linux干货 2016-08-05
  • python 10第一周博客作业

    1. 修改提示符格式 PS1=”\[\e[1;5;41;33m\][\u@\h \W]\\$\[\e[0m\]” 2.命令别名:alias NAME=’VALUE’   如果想永久有效,要定义在配置文件中 仅对当前用户:~/.bashrc   对所有用户有效:/etc/bashrc 3.日期和时间:相关命令 d…

    Linux干货 2018-03-17
  • mongodb 分片集群搭建

    集群架构 本次实验部署3台主机node1、node2、node3,2个副本集db1、db2作为分片,3台主机均有1个配置库实例 操作步骤 安装 node1上执行如下命令,完成后拷贝/mongodb目录到node2、node3 useradd mongodb   mkdir -p /mongodb/data/{…

    Linux干货 2016-11-06
  • 第八周作业

    shell脚本简用

    Linux干货 2017-11-27
  • 马哥教育网络班21期-第四周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -a /etc/skel/ /home/tuser1 chmod -R 700 /home/tuser1/  2、编辑/etc/group文件,添加组hadoop。 echo "hadoop:x:2…

    Linux干货 2016-08-05
  • puppet部署多台服务器

    利用puppet实现自动化部署 配置前准备:   图中:蓝线表示各个服务器之间通信      红线表示puppetmaster主机向各个agent主机部署信道 A主机puppet-master主机:192.168.126.129 B主机做两种服务:keepalived高性能和nginx反代  &nb…

    2017-07-23