32、程序包管理之三-yum

32.1 yum简介

        CentOS:yum,dnf

        URL:yum仓库路径

        YUM:yellow dog,Yellowdog Update Modifier

32.2 repository

        1、yum repository: yum repo

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

        2、文件服务器

                ftp://

                http://

                nfs://

                file://

        3、yum 客户端:

                配置文件:

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

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

                [root@localhost cd-rom]# rpm -qc yum

                /etc/logrotate.d/yum

                /etc/yum.conf

                /etc/yum/version-groups.conf

                仓库指向的定义:

                [repositoryID]

                        name=Some name for this respository

                        baseurl=url://path/to/respository/

                        enabled={1|0}

                        gpgcheck={1|0}

                        gpgkey=URL

                        enablegroups={1|0}

                        failovermethod={roundrobin|priority}

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

                        cost=

                        默认为1000

        4、yum命令的用法

                yum [options] [command] package

        显示仓库列表

                yum repolist [all|enabled|disabled]:显示仓库列表

                [root@localhost cd-rom]# yum repolist all

                Loaded plugins: fastestmirror, langpacks

                Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                repo id                     repo name                    status

                C7.0.1406-base/x86_64       CentOS-7.0.1406 - Base       disabled

                C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus disabled

                C7.0.1406-extras/x86_64     CentOS-7.0.1406 - Extras     disabled

                C7.0.1406-fasttrack/x86_64  CentOS-7.0.1406 - CentOSPlus disabled

                C7.0.1406-updates/x86_64    CentOS-7.0.1406 - Updates    disabled

                C7.1.1503-base/x86_64       CentOS-7.1.1503 - Base       disabled

                C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus disabled

                C7.1.1503-extras/x86_64     CentOS-7.1.1503 - Extras     disabled

                C7.1.1503-fasttrack/x86_64  CentOS-7.1.1503 - CentOSPlus disabled

                C7.1.1503-updates/x86_64    CentOS-7.1.1503 - Updates    disabled

                C7.2.1511-base/x86_64       CentOS-7.2.1511 - Base       disabled

                C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus disabled

                C7.2.1511-extras/x86_64     CentOS-7.2.1511 - Extras     disabled

                C7.2.1511-fasttrack/x86_64  CentOS-7.2.1511 - CentOSPlus disabled

                C7.2.1511-updates/x86_64    CentOS-7.2.1511 - Updates    disabled

                C7.3.1611-base/x86_64       CentOS-7.3.1611 - Base       disabled

                C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 - CentOSPlus disabled

                C7.3.1611-extras/x86_64     CentOS-7.3.1611 - Extras     disabled

                C7.3.1611-fasttrack/x86_64  CentOS-7.3.1611 - CentOSPlus disabled

                C7.3.1611-updates/x86_64    CentOS-7.3.1611 - Updates    disabled

                !base/7/x86_64              CentOS-7 - Base              enabled: 10,072

                base-debuginfo/x86_64       CentOS-7 - Debuginfo         disabled

                base-source/7               CentOS-7 - Base Sources      disabled

                c7-media                    CentOS-7 - Media             disabled

                centosplus/7/x86_64         CentOS-7 - Plus              disabled

                centosplus-source/7         CentOS-7 - Plus Sources      disabled

                cr/7/x86_64                 CentOS-7 - cr                disabled

                !extras/7/x86_64            CentOS-7 - Extras            enabled:    476

                extras-source/7             CentOS-7 - Extras Sources    disabled

                fasttrack/7/x86_64          CentOS-7 - fasttrack         disabled

                !updates/7/x86_64           CentOS-7 - Updates           enabled:  2,189

                updates-source/7            CentOS-7 - Updates Sources   disabled

                repolist: 12,737

                [root@localhost cd-rom]# 

        显示程序包

                yum list [all|glob_exp]:显示所有程序包或者自定义的程序包

                yum list {avaliable|installed|updates} [glob_exp]

                [root@localhost cd-rom]# yum list all | head -20

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Installed Packages

                GConf2.x86_64                               3.2.6-8.el7                @anaconda

                GeoIP.x86_64                                1.5.0-11.el7               @anaconda

                ModemManager.x86_64                         1.6.0-2.el7                @anaconda

                ModemManager-glib.x86_64                    1.6.0-2.el7                @anaconda

                NetworkManager.x86_64                       1:1.8.0-9.el7              @anaconda

                NetworkManager-adsl.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-glib.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-libnm.x86_64                 1:1.8.0-9.el7              @anaconda

                NetworkManager-libreswan.x86_64             1.2.4-2.el7                @anaconda

                NetworkManager-libreswan-gnome.x86_64       1.2.4-2.el7                @anaconda

                NetworkManager-ppp.x86_64                   1:1.8.0-9.el7              @anaconda

                NetworkManager-team.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-tui.x86_64                   1:1.8.0-9.el7              @anaconda

                NetworkManager-wifi.x86_64                  1:1.8.0-9.el7              @anaconda

                Exiting on Broken Pipe

                [root@localhost cd-rom]# 

        安装程序包

                yum install package

                yum reinstall package重新安装

                [root@localhost cd-rom]# yum reinstall zsh

                Loaded plugins: fastestmirror, langpacks

                No Match for argument: zsh

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Package(s) zsh available, but not installed.

                Error: Nothing to do

                [root@localhost cd-rom]# yum install zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Resolving Dependencies

                --> Running transaction check

                ---> Package zsh.x86_64 0:5.0.2-34.el7_8.2 will be installed

                --> Finished Dependency Resolution

                Dependencies Resolved

                ===============================================================================================================================================================

                 Package                          Arch                                Version                                          Repository                         Size

                ===============================================================================================================================================================

                Installing:

                 zsh                              x86_64                              5.0.2-34.el7_8.2                                 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:

                zsh-5.0.2-34.el7_8.2.x86_64.rpm                                                                                                         | 2.4 MB  00:00:03     

                Running transaction check

                Running transaction test

                Transaction test succeeded

                Running transaction

                  Installing : zsh-5.0.2-34.el7_8.2.x86_64                                                                                                                 1/1 

                  Verifying  : zsh-5.0.2-34.el7_8.2.x86_64                                                                                                                 1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-34.el7_8.2                                                                                                                                

                Complete!

                [root@localhost cd-rom]# 

        升级程序包

                yum update package

                yum downgrade package降级程序包

                [root@localhost cd-rom]# yum update zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                No packages marked for update

                [root@localhost cd-rom]# yum downgrade zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Nothing to do

                [root@localhost cd-rom]# 

        检查可用升级

                yum check-update package

                [root@localhost cd-rom]# yum check-update python

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                python.x86_64                                  2.7.5-90.el7                                  updates

                [root@localhost cd-rom]# 

        卸载程序包

                yum remove|erase package

                [root@localhost cd-rom]# yum remove zsh.x86_64 

                Loaded plugins: fastestmirror, langpacks

                Resolving Dependencies

                --> Running transaction check

                ---> Package zsh.x86_64 0:5.0.2-34.el7_8.2 will be erased

                --> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package           Arch                 Version                           Repository           Size

                ====================================================================================================

                Removing:

                 zsh               x86_64               5.0.2-34.el7_8.2                  @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-34.el7_8.2.x86_64                                                      1/1 

                  Verifying  : zsh-5.0.2-34.el7_8.2.x86_64                                                      1/1 

                Removed:

                  zsh.x86_64 0:5.0.2-34.el7_8.2                                                                     

                Complete!

                [root@localhost cd-rom]# 

        查看程序包information

                yum info package

                [root@localhost cd-rom]# yum info zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Installed Packages

                Name        : zsh

                Arch        : x86_64

                Version     : 5.0.2

                Release     : 34.el7_8.2

                Size        : 5.6 M

                Repo        : installed

                From repo   : base

                Summary     : Powerful interactive shell

                URL         : http://zsh.sourceforge.net/

                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.

                [root@localhost cd-rom]# 

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

                yum provides|whatprovides package

                [root@localhost cd-rom]# yum provides zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : base

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : @base

                [root@localhost cd-rom]# yum whatprovides zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : base

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : @base

                [root@localhost cd-rom]# 

        清理本地缓存

                yum clean all|packages|metadate…

                [root@localhost cd-rom]# yum clean all

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: base extras updates

                Cleaning up everything

                Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

                Cleaning up list of fastest mirrors

                [root@localhost cd-rom]# yum clean zsh

                Loaded plugins: fastestmirror, langpacks

                Error: invalid clean argument: 'zsh'

                 Mini usage:

                clean [headers|packages|metadata|dbcache|plugins|expire-cache|all]

                Remove cached data

                [root@localhost cd-rom]# yum clean packages 

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: base extras updates

                0 package files removed

                [root@localhost cd-rom]# 

        构建缓存

                yum makecache

                [root@localhost cd-rom]# yum makecache

                Loaded plugins: fastestmirror, langpacks

                base                                                                         | 3.6 kB  00:00:00     

                extras                                                                       | 2.9 kB  00:00:00     

                updates                                                                      | 2.9 kB  00:00:00     

                (1/10): base/7/x86_64/primary_db                                             | 6.1 MB  00:00:00     

                (2/10): base/7/x86_64/group_gz                                               | 153 kB  00:00:01     

                (3/10): extras/7/x86_64/filelists_db                                         | 235 kB  00:00:00     

                (4/10): updates/7/x86_64/filelists_db                                        | 5.5 MB  00:00:00     

                (5/10): updates/7/x86_64/primary_db                                          | 9.5 MB  00:00:00     

                (6/10): extras/7/x86_64/primary_db                                           | 242 kB  00:00:00     

                (7/10): updates/7/x86_64/other_db                                            | 681 kB  00:00:00     

                (8/10): extras/7/x86_64/other_db                                             | 143 kB  00:00:01     

                (9/10): base/7/x86_64/other_db                                               | 2.6 MB  00:00:03     

                (10/10): base/7/x86_64/filelists_db                                          | 7.2 MB  00:00:07     

                Determining fastest mirrors

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                Metadata Cache Created

                [root@localhost cd-rom]# 

        搜索

                yum search string

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

                [root@localhost cd-rom]# yum search zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                ========================================= N/S matched: zsh =========================================

                zsh-html.x86_64 : Zsh shell manual in html format

                zsh.x86_64 : Powerful interactive shell

                  Name and summary matches only, use "search all" for everything.

                [root@localhost cd-rom]# 

        查看指定报名所依赖的compabilities;

                yum deplist package

                [root@localhost cd-rom]# yum deplist zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                package: zsh.x86_64 5.0.2-34.el7_8.2

                  dependency: /bin/sh

                   provider: bash.x86_64 4.2.46-34.el7

                  dependency: /sbin/install-info

                   provider: info.x86_64 5.1-5.el7

                  dependency: coreutils

                   provider: coreutils.x86_64 8.22-24.el7_9.2

                  dependency: grep

                   provider: grep.x86_64 2.20-3.el7

                  dependency: libc.so.6(GLIBC_2.15)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libdl.so.2()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libm.so.6()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libm.so.6(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libncursesw.so.5()(64bit)

                   provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4

                  dependency: librt.so.1()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: librt.so.1(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libtinfo.so.5()(64bit)

                   provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4

                  dependency: rtld(GNU_HASH)

                   provider: glibc.x86_64 2.17-324.el7_9

                   provider: glibc.i686 2.17-324.el7_9

                [root@localhost cd-rom]# 

        查看yum事务历史

                yum history

                [root@localhost cd-rom]# yum history 

                Loaded plugins: fastestmirror, langpacks

                ID     | Login user               | Date and time    | Action(s)      | Altered

                -------------------------------------------------------------------------------

                     9 | root <root>              | 2021-08-02 23:39 | Install        |    1   

                     8 | root <root>              | 2021-08-02 23:38 | Erase          |    1   

                     7 | root <root>              | 2021-08-02 23:35 | Install        |    1   

                     6 | root <root>              | 2021-08-02 23:35 | Erase          |    1 E<

                     5 |  <oracle>                | 2021-05-26 00:05 | Install        |    1 > 

                     4 |  <oracle>                | 2021-05-25 23:48 | Install        |    1   

                     3 |  <oracle>                | 2021-05-25 22:58 | I, U           |   11   

                     2 | daniel <daniel>          | 2021-05-25 22:26 | I, U           |   41 EE

                     1 | System <unset>           | 2021-05-19 21:06 | Install        | 1255   

                history list

                [root@localhost cd-rom]# 

        安装及升级本地程序包

                yum localinstall rpmfile

                yum localupdate rpmfile

                [root@localhost cd-rom]# yum localinstall ./Packages/zsh-5.0.2-28.el7.x86_64.rpm 

                Loaded plugins: fastestmirror, langpacks

                Examining ./Packages/zsh-5.0.2-28.el7.x86_64.rpm: zsh-5.0.2-28.el7.x86_64

                Marking ./Packages/zsh-5.0.2-28.el7.x86_64.rpm to be installed

                Resolving Dependencies

                --> Running transaction check

                ---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed

                --> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package        Arch              Version                 Repository                           Size

                ====================================================================================================

                Installing:

                 zsh            x86_64            5.0.2-28.el7            /zsh-5.0.2-28.el7.x86_64            5.6 M

                Transaction Summary

                ====================================================================================================

                Install  1 Package

                Total size: 5.6 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-28.el7.x86_64                                                          1/1 

                  Verifying  : zsh-5.0.2-28.el7.x86_64                                                          1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-28.el7                                                                         

                Complete!

                [root@localhost cd-rom]# 

        包组管理的相关命令

                groupinstall

                groupupdate

                grouplist

                groupremove

                groupinfo

                [root@localhost cd-rom]# yum grouplist

                Loaded plugins: fastestmirror, langpacks

                There is no installed groups file.

                Maybe run: yum groups mark convert (see man yum)

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                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

                Available Groups:

                   Compatibility Libraries

                   Console Internet Tools

                   Development Tools

                   Graphical Administration Tools

                   Legacy UNIX Compatibility

                   Scientific Support

                   Security Tools

                   Smart Card Support

                   System Administration Tools

                   System Management

                Done

                [root@localhost cd-rom]# yum groupinstall "Basic Web Server"

                Loaded plugins: fastestmirror, langpacks

                There is no installed groups file.

                Maybe run: yum groups mark convert (see man yum)

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                Resolving Dependencies

                --> Running transaction check

                ---> Package bpftool.x86_64 0:3.10.0-1160.36.2.el7 will be installed

                ---> Package crypto-utils.x86_64 0:2.4.1-42.el7 will be installed

                --> Processing Dependency: perl(Newt) for package: crypto-utils-2.4.1-42.el7.x86_64

                --> Processing Dependency: kernel(___ratelimit) = 0x155f4108 for package: kmod-kvdo-6.1.3.23-5.el7.x86_64

                --> Processing Dependency: kernel >= 3.10.0-1133.el7 for package: kmod-kvdo-6.1.3.23-5.el7.x86_64

                ---> Package lshw.x86_64 0:B.02.18-17.el7 will be installed

                ---> Package mod_fcgid.x86_64 0:2.3.9-6.el7 will be installed

                ---> Package libselinux-utils.x86_64 0:2.5-15.el7 will be an update

                --> Processing Dependency: libselinux(x86-64) = 2.5-15.el7 for package: libselinux-utils-2.5-15.el7.x86_64

                ---> Package libsemanage.x86_64 0:2.5-8.el7 will be updated

                --> Processing Dependency: libsemanage = 2.5-8.el7 for package: libsemanage-python-2.5-11.el7.x86_64

                ---> Package libselinux.x86_64 0:2.5-15.el7 will be an update

                ---> Package libsemanage-python.x86_64 0:2.5-8.el7 will be updated

                ---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be an update

                ---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be updated

                ---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be an update

                --> Running transaction check

                ---> Package libselinux-python.x86_64 0:2.5-11.el7 will be updated

                ---> Package libselinux-python.x86_64 0:2.5-15.el7 will be an update

                --> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package                       Arch         Version                             Repository     Size

                ====================================================================================================

                64       2.4.6-97.el7.centos                 updates        93 k

                 libyaml                       x86_64       0.1.4-11.el7_0                      base           55 k

                 mailcap                       noarch       2.1.41-2.el7                        base           31 k

                 perl-Newt                     x86_64       1.08-36.el7                         base           64 k

                Updating for dependencies:

                 libselinux                    x86_64       2.5-15.el7                          base          162 k

                 libselinux-python             x86_64       2.5-15.el7                          base          236 k

                 libselinux-utils              x86_64       2.5-15.el7                          base          151 k

                 libsemanage                   x86_64       2.5-14.el7                          base          151 k

                 libsemanage-python            x86_64       2.5-14.el7                          base          113 k

                 libsepol                      x86_64       2.5-10.el7                          base          297 k

                 linux-firmware                noarch       20200421-80.git78c0348.el7_9        updates        80 M

                 policycoreutils               x86_64       2.5-34.el7                          base          917 k

                 policycoreutils-python        x86_64       2.5-34.el7                          base          457 k

                 python                        x86_64       2.7.5-90.el7                        updates        96 k

                 python-libs                   x86_64       2.7.5-90.el7                        updates       5.6 M

                 selinux-policy                noarch       3.13.1-268.el7_9.2                  updates       498 k

                 setools-libs                  x86_64       3.3.8-4.el7                         base          620 k

                 sg3_utils-libs                x86_64       1:1.37-19.el7                       base           65 k

                Transaction Summary

                ====================================================================================================

                Install  11 Packages (+ 7 Dependent packages)

                Upgrade   1 Package  (+14 Dependent packages)

                Total download size: 162 M

                Is this ok [y/d/N]: 

32.3 本地yum仓库配置

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

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

                        [root@localhost /]# mkdir /media/cdrom

                        [root@localhost /]# mount -r -t iso9660 /dev/cdrom /media/cdrom

                (2)创建配置文件

                        [base]

                        name=CentOSlocal

                        #mirrorlist=file:///opt/yum.repo/

                        baseurl=file:///media/cdrom

                        gpgcheck=1

                        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

        2、yum的命令行选项

                --nogpgcheck:禁止进行gpg check

                --y:自动回复yes

                --q:静默模式

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

                --enablerepo=repoidglob:临时禁用此处指定的repo;

                --noplugins:禁用所有插件

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

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

                $arch:平台

                $basearch:基础平台

                $YUM0-$YUM9

        4、创建yum仓库

                createrepo [options] <directory>

                repo格式

                        [base]

                        name=CentOS-$releasever - test

                        #mirrorlist=file:///opt/yum.repo

                        baseurl=file:///opt/yum.repo

                        gpgcheck=1

                        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

                [root@localhost yum.repo]# createrepo /opt/yum.repo/

                Spawning worker 0 with 974 pkgs

                Spawning worker 1 with 974 pkgs

                Spawning worker 2 with 973 pkgs

                Spawning worker 3 with 973 pkgs

                Workers Finished

                Saving Primary metadata

                Saving file lists metadata

                Saving other metadata

                Generating sqlite DBs

                Sqlite DBs complete

                [root@localhost yum.repo]# yum clean all

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: base

                Cleaning up everything

                Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

                [root@localhost yum.repo]# rm -rf /var/cache/yum

                [root@localhost yum.repo]# vim /etc/yum.repos.d/CentOS-Base.repo 

                [root@localhost yum.repo]# yum repolist 

                Loaded plugins: fastestmirror, langpacks

                base                                                                                                                                    | 2.9 kB  00:00:00     

                base/primary_db                                                                                                                         | 3.0 MB  00:00:00     

                Determining fastest mirrors

                repo id                                                                 repo name                                                                        status

                base                                                                    CentOS-7 - test                                                                  3,894

                repolist: 3,894

                [root@localhost yum.repo]# ll /opt/yum.repo/ | wc -l

                3897

                [root@localhost yum.repo]# yum install z

                zenity-3.22.0-1.el7.x86_64.rpm      zlib-devel-1.2.7-17.el7.x86_64.rpm  zsh.x86_64                          

                zip-3.0-11.el7.x86_64.rpm           zlib-devel.x86_64                   zziplib-0.13.62-5.el7.x86_64.rpm    

                zlib-1.2.7-17.el7.x86_64.rpm        zsh-5.0.2-28.el7.x86_64.rpm         zziplib.x86_64                      

                [root@localhost yum.repo]# yum install z

                zenity-3.22.0-1.el7.x86_64.rpm      zlib-devel-1.2.7-17.el7.x86_64.rpm  zsh.x86_64                          

                zip-3.0-11.el7.x86_64.rpm           zlib-devel.x86_64                   zziplib-0.13.62-5.el7.x86_64.rpm    

                zlib-1.2.7-17.el7.x86_64.rpm        zsh-5.0.2-28.el7.x86_64.rpm         zziplib.x86_64                      

                [root@localhost yum.repo]# yum install zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                Resolving Dependencies

                --> Running transaction check

                ---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed

                --> Finished Dependency Resolution

                Dependencies Resolved

                ===============================================================================================================================================================

                 Package                           Arch                                 Version                                       Repository                          Size

                ===============================================================================================================================================================

                Installing:

                 zsh                               x86_64                               5.0.2-28.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-28.el7.x86_64                                                                                                                     1/1 

                  Verifying  : zsh-5.0.2-28.el7.x86_64                                                                                                                     1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-28.el7                                                                                                                                    

                Complete!

                [root@localhost yum.repo]# yum list | grep zsh

                zsh.x86_64                              5.0.2-28.el7                   @base    

                [root@localhost yum.repo]# 

评论关闭。