yum仓库搭建分为以下几步骤:

1、搜集rpm包

2、安装httpd 服务

3、生成rpm包的依赖关系

4、创建配置文件

5、测试

 

步骤:

首先检查系统的版本:

[root@m01 ~]# uname -r
2.6.32-573.el6.x86_64
[root@m01 ~]# cat /etc/centos-release 
CentOS release 6.7 (Final)

 1、搜集rpm包

[root@web02 ~]# grep "keepcache=0" /etc/yum.conf 
keepcache=0
[root@web02 ~]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf 
[root@web02 ~]# grep "keepcache=1" /etc/yum.conf 
keepcache=1
提前创建好目录,把所有的rpm包都统一放到/var/www/html/centos下(httpd 的默认访问路径是/var/www/html)
[root@m01 yum.repos.d]# mkdir  /var/www/html/centos

修改keepcache=1后,以后每次再yum安装的rpm包都会默认存到本地,使用

find / -type f -name "*.rpm" |xargs -i mv {} /var/www/html/centos
 [root@web02 yum.repos.d]# yumdownloader dhcp
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
centos                                                                                                        | 2.9 kB     00:00     
centos/primary_db                                                                                             |  56 kB     00:00     
dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm                                                                        | 823 kB     00:00     
[root@web02 yum.repos.d]# ls
bak  dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm  oldboy.repo

 2、安装httpd 服务

[root@m01 yum.repos.d]# yum -y install httpd
[root@m01 ~]# /etc/init.d/httpd start
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using 172.16.1.61 for ServerName
                                                           [确定]

3、生成rpm包的依赖关系

[root@m01 html]# cd /var/www/html/centos/
[root@m01 centos]# createrepo .    #使用createrepo命令生成rpm包依赖关系
Spawning worker 0 with 78 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@m01 centos]# ls repodata/     #当前目录下会自动创建repodata目录,目录内有以下文件
285b777c14d998d3e74320f744a7d9b4f19878960caaf43ffb4f4bec4b2c28e0-filelists.xml.gz
702c65d1e7598653eb04b7c964caf7a0c50eb39aa7f90fb298824f73186bd2d2-filelists.sqlite.bz2
83de689974912c613cbe052307ca736e49c51d36cb008f1012793ae95aee1fa2-primary.sqlite.bz2
b1e874353d11d75247937b73761a47de5a0b21af1ac2fe1a12f17b83e9e018c0-other.sqlite.bz2
bc994749d127935f2aadef680edce4922d2d590bca1dbad8a8982872426a88ef-other.xml.gz
e34bfa8116770f2b12eba92c08a5ef00b3f0b72e1d6ee65c9b39a08c844ae89d-primary.xml.gz
repomd.xml

当yum仓库包更新了以后,使用“createrepo --update  rpm包目录” 命令更新yum 仓库包的依赖关系

4、创建配置文件(名字随意,只要是以.repo结尾的就可以)

 [root@m01 ~]# cat /etc/yum.repos.d/oldboy.repo 
[oldboyedu]                             
name=Server
baseurl=http://10.0.0.61/centos
enable=1
gpgcheck=0

 说明:

[oldboyedu]                          #仓库名称             
name=Server                          #名称随便写
baseurl=http://10.0.0.61/centos      #yum仓库的地址 如果是本机使用的话,可以写成 baseurl=file:///var/www/html/centos/  是通用地址,本机可以这样设置,客户端也是这样设置
enable=1                             #启用仓库
gpgcheck=0                           #不启用校验

 5、测试

使用yum list 可以显示出仓库里的所有安装包和可以安装的哪些包,此刻yum仓库搭建成功

[root@m01 centos]# yum list
已加载插件:fastestmirror, security
Loading mirror speeds from cached hostfile
已安装的软件包
ConsoleKit.x86_64                               0.4.1-3.el6                                  @anaconda-CentOS-201508042137.x86_64/6.7
ConsoleKit-libs.x86_64                          0.4.1-3.el6                                  @anaconda-CentOS-201508042137.x86_64/6.7
MAKEDEV.x86_64                                  3.24-6.el6                                   @anaconda-CentOS-201508042137.x86_64/6.7
 .....
可安装的软件包
curl.x86_64                                     7.19.7-52.el6                                oldboyedu                               
dhclient.x86_64                                 12:4.1.1-51.P1.el6.centos                    oldboyedu                               
dhcp.x86_64                                     12:4.1.1-51.P1.el6.centos                    oldboyedu                               
dhcp-common.x86_64                              12:4.1.1-51.P1.el6.centos                    oldboyedu                               
fontconfig-devel.x86_64                         2.8.0-5.el6                                  oldboyedu                               
freetype.x86_64                                 2.3.11-17.el6                                oldboyedu

 安装软件包:

[root@m01 ~]# yum -y install dhcp
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
解决依赖关系
--> 执行事务检查
---> Package dhcp.x86_64 12:4.1.1-51.P1.el6.centos will be 安装
--> 处理依赖关系 dhcp-common = 12:4.1.1-51.P1.el6.centos,它被软件包 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 需要
--> 处理依赖关系 portreserve,它被软件包 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 需要
--> 执行事务检查
---> Package dhcp-common.x86_64 12:4.1.1-49.P1.el6.centos will be 升级
--> 处理依赖关系 dhcp-common = 12:4.1.1-49.P1.el6.centos,它被软件包 12:dhclient-4.1.1-49.P1.el6.centos.x86_64 需要
---> Package dhcp-common.x86_64 12:4.1.1-51.P1.el6.centos will be an update
---> Package portreserve.x86_64 0:0.0.4-11.el6 will be 安装
--> 执行事务检查
---> Package dhclient.x86_64 12:4.1.1-49.P1.el6.centos will be 升级
---> Package dhclient.x86_64 12:4.1.1-51.P1.el6.centos will be an update
--> 完成依赖关系计算
依赖关系解决
=====================================================================================================================================
 软件包                       架构                    版本                                          仓库                        大小
=====================================================================================================================================
正在安装:
 dhcp                         x86_64                  12:4.1.1-51.P1.el6.centos                     oldboyedu                  823 k
为依赖而安装:
 portreserve                  x86_64                  0.0.4-11.el6                                  oldboyedu                   23 k
为依赖而更新:
 dhclient                     x86_64                  12:4.1.1-51.P1.el6.centos                     oldboyedu                  321 k
 dhcp-common                  x86_64                  12:4.1.1-51.P1.el6.centos                     oldboyedu                  144 k
事务概要
=====================================================================================================================================
Install       2 Package(s)
Upgrade       2 Package(s)
总下载量:1.3 M
下载软件包:
(1/4): dhclient-4.1.1-51.P1.el6.centos.x86_64.rpm                                                             | 321 kB     00:00     
(2/4): dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm                                                                 | 823 kB     00:00     
(3/4): dhcp-common-4.1.1-51.P1.el6.centos.x86_64.rpm                                                          | 144 kB     00:00     
(4/4): portreserve-0.0.4-11.el6.x86_64.rpm                                                                    |  23 kB     00:00     
-------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                  16 MB/s | 1.3 MB     00:00     
运行 rpm_check_debug 
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
  正在升级   : 12:dhcp-common-4.1.1-51.P1.el6.centos.x86_64                                                                      1/6 
  正在安装   : portreserve-0.0.4-11.el6.x86_64                                                                                   2/6 
  正在安装   : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64                                                                             3/6 
  正在升级   : 12:dhclient-4.1.1-51.P1.el6.centos.x86_64                                                                         4/6 
  清理       : 12:dhclient-4.1.1-49.P1.el6.centos.x86_64                                                                         5/6 
  清理       : 12:dhcp-common-4.1.1-49.P1.el6.centos.x86_64                                                                      6/6 
  Verifying  : 12:dhclient-4.1.1-51.P1.el6.centos.x86_64                                                                         1/6 
  Verifying  : portreserve-0.0.4-11.el6.x86_64                                                                                   2/6 
  Verifying  : 12:dhcp-common-4.1.1-51.P1.el6.centos.x86_64                                                                      3/6 
  Verifying  : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64                                                                             4/6 
  Verifying  : 12:dhcp-common-4.1.1-49.P1.el6.centos.x86_64                                                                      5/6 
  Verifying  : 12:dhclient-4.1.1-49.P1.el6.centos.x86_64                                                                         6/6