配置一个yum仓库

[repo-id]  标识

name= 

# 当前仓库描述信息;

baseurl=url://path/to/repository/

# 指明repository的访问路径;通常为一个文件服务器上输出的某repository;


url:

ftp服务

            ftp://SERVER/PATH/TO/REPOSITORY

http服务

    http://SERVER/PATH/TO/REPOSITORY

本地目录:

    file:///PATH/TO/REPOSTIROY


enabled={1|0}

此仓库是否可被使用

gpgcheck={1|0}

是否对程序包做校验

gpgkey=url://path/to/keyfile

指明gpgkey文件路径;

cost=#

指明当前repository的访问开销,默认为1000;

[httpd]
name=httpd
baseurl=http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/
enabled=1
gpgcheck=0

yum命令的可用选项:

    -y: 自动回答为“yes”

    --disablerepo=: 临时禁用在配置文件中配置并启用的某repository;

    --enablerepo=:临时启用指定的某repo;

    --nogpgcheck: 禁止做包校验



repolist: 列出已经配置的所有可用仓库

    repolist [all|enabled|disabled]

#yum repolist




makecache: 缓存创建

    自动连接至每一个可用仓库,下载其无数据,将其创建为缓存;

[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
dvd                                                                                  | 4.0 kB     00:00 ... 
cd/filelists_db                                                                     | 6.0 MB     00:00 ... 
cd/other_db                                                                         | 2.8 MB     00:00 ... 
ftp                                                                                 | 2.9 kB     00:00     
httpd                                                                               | 3.0 kB     00:00     
httpd/other_db                                                                      | 4.3 MB     00:01     
base                                                                                | 2.9 kB     00:00     
base/other_db                                                                       | 965 kB     00:00     
Metadata Cache Created
[root@localhost yum.repos.d]#


程序包安装:

    install package1 [package2] [...]

[root@localhost yum.repos.d]# yum install php
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-38.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch                     Version                         Repository            Size
===========================================================================================================
Installing:
 php                   x86_64                   5.3.3-38.el6                    cd                   1.1 M

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

Total download size: 1.1 M
Installed size: 3.5 M
Is this ok [y/N]: 在此键入y表示安装,键入n表示放弃安装


  重新安装(覆盖安装)

    reinstall package1 [package2] [...]


    程序包升级:

    update [package1] [package2] [...]


    程序包降级:

    downgrade package1 [package2] [...]


    检查有哪些升级可用:

    check-update


    卸载:

    remove | erase package1 [package2] [...]

    查询:

    查询程序的相关简要信息:info PACKAGE

[root@localhost yum.repos.d]# yum  info nginx
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name        : nginx
Arch        : x86_64
Version     : 1.6.2
Release     : 1.el6.ngx
Size        : 828 k
Repo        : installed
Summary     : High performance web server
URL         : http://nginx.org/
License     : 2-clause BSD-like license
Description : nginx [engine x] is an HTTP and reverse proxy server, as well as
            : a mail proxy server.


包组管理:

    列出所有包组:grouplist

[root@localhost yum.repos.d]# yum grouplist
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
Installed Groups:
   Additional Development
   Base
   Console internet tools
   Desktop
   Development tools
   Dial-up Networking Support
   Directory Client
   E-mail server
   FTP server
   Fonts
   General Purpose Desktop
   Graphical Administration Tools
   Hardware monitoring utilities
   Input Methods
   Internet Browser
   Legacy UNIX compatibility
   Legacy X Window System compatibility
   MySQL Database client
   MySQL Database server
   NFS file server
   Network Infrastructure Server
   Network file system client
   Networking Tools
   PHP Support
   Performance Tools
   Perl Support
   Security Tools
   System administration tools
   Web Server
   X Window System
Installed Language Groups:
   Arabic Support [ar]
   Armenian Support [hy]
   Bhutanese Support [dz]
   Chinese Support [zh]
   Ethiopic Support [am]
   Georgian Support [ka]
   Hebrew Support [he]
   Inuktitut Support [iu]
   Japanese Support [ja]
   Khmer Support [km]
   Konkani Support [kok]
   Korean Support [ko]
   Kurdish Support [ku]
   Lao Support [lo]
   Myanmar (Burmese) Support [my]
   Tajik Support [tg]
   Venda Support [ve]
Available Groups:
   Backup Client
Done

    显示指定包组详情:groupinfo group1 [...]


    安装:groupinstall group1 [group2] [...]


    卸载:groupremove group1 [group2] [...]


    升级:groupupdate group1 [group2] [...]


示例:搭建一个xen的yum仓库。

安装httpd,用来存放软件包

[root@localhost yum.repos.d]# yum install httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package              Arch                  Version                                Repository         Size
===========================================================================================================
Installing:
 httpd                x86_64                2.2.15-39.el6.centos                   cd                825 k

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

Total download size: 825 k
Installed size: 2.9 M
Is this ok [y/N]:

下载xen相关的rpm包

[root@localhost ~]# cd /var/www/html/xen
[root@localhost html]# lftp 172.16.0.1
lftp 172.16.0.1:~> cd /pub/Sources/6.x86_64/xen-4.1/
cd ok, cwd=/pub/Sources/6.x86_64/xen-4.1             
lftp 172.16.0.1:/pub/Sources/6.x86_64/xen-4.1> ls
-rw-r--r--    1 0        0           29900 Feb 04 04:51 bridge-utils-1.5-2.el6.x86_64.rpm
-rw-r--r--    1 0        0           36412 Feb 04 04:57 bridge-utils-debuginfo-1.5-2.el6.x86_64.rpm
-rw-r--r--    1 0        0        26657636 Feb 04 04:50 kernel-xen-3.14.31-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0        19565560 Feb 04 04:57 kernel-xen-3.7.4-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0         9406304 Feb 04 04:50 kernel-xen-devel-3.14.31-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0         8529216 Feb 04 04:57 kernel-xen-devel-3.7.4-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0        33730316 Feb 04 04:50 kernel-xen-firmware-3.14.31-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0         1028720 Feb 04 04:57 kernel-xen-firmware-3.7.4-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0          908388 Feb 04 04:50 kernel-xen-headers-3.14.31-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0          844524 Feb 04 04:57 kernel-xen-headers-3.7.4-1.el6xen.x86_64.rpm
-rw-r--r--    1 0        0           10056 Feb 04 04:57 kernel-xen-release-6-4.noarch.rpm
drwxr-xr-x    2 0        0            4096 Feb 04 04:57 repodata
-rw-r--r--    1 0        0         1100320 Feb 04 04:49 xen-4.1.3-2.el6.x86_64.rpm
-rw-r--r--    1 0        0         1040052 Feb 04 04:55 xen-4.2.1-1.el6.x86_64.rpm
-rw-r--r--    1 0        0         1040284 Feb 04 04:55 xen-4.2.1-2.el6.x86_64.rpm
-rw-r--r--    1 0        0         3317700 Feb 04 04:49 xen-debuginfo-4.1.3-2.el6.x86_64.rpm
-rw-r--r--    1 0        0         3228360 Feb 04 04:55 xen-debuginfo-4.2.1-2.el6.x86_64.rpm
-rw-r--r--    1 0        0          172844 Feb 04 04:49 xen-devel-4.1.3-2.el6.x86_64.rpm
-rw-r--r--    1 0        0          178800 Feb 04 04:55 xen-devel-4.2.1-1.el6.x86_64.rpm
-rw-r--r--    1 0        0          179012 Feb 04 04:55 xen-devel-4.2.1-2.el6.x86_64.rpm
-rw-r--r--    1 0        0          894736 Feb 04 04:49 xen-doc-4.1.3-2.el6.x86_64.rpm
...........................................................................................................................................
lftp 172.16.0.1:/pub/Sources/6.x86_64/xen-4.1> mget *.rpm
146543076 bytes transferred in 34 seconds (4.06M/s)                                     
Total 41 files transferred
lftp 172.16.0.1:/pub/Sources/6.x86_64/xen-4.1> quit

如果内网没有xen相关的包,需要连接外网进行下载。

下载完成创建repodata数据库

[root@localhost xen]# createrepo /var/www/html/xen
Spawning worker 0 with 82 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

创建完成数据库之后启动httpd服务

[root@localhost xen]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localho
st.localdomain for ServerName                                                           [  OK  ]

编辑yum的配置文件,添加自己建立的yum仓库信息

[root@localhost xen]# vim/etc/yum.repos.d/centos6.6.repo
[httpd]
name=httpd
baseurl=http://172.16.4.100/pub/
gpgcheck=0
enable=1
[root@localhost xen]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                repo name                                          status
http                   httpd                                                  41

安装xen

[root@localhost html]# yum install xen
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package xen.x86_64 0:4.2.1-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch                     Version                        Repository             Size
===========================================================================================================
Installing:
 xen                   x86_64                   4.2.1-2.el6                    ftp                   1.0 M

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

Total download size: 1.0 M
Installed size: 4.3 M
Is this ok [y/N]: