本文记录创建自定义yum仓库,目的为方便安装定制的rpm包及开源组件版本统一。

一、Build Local Repository

1、搭建web服务,自己定制的rpm包tengine,所以安装起来就很简单了。

#cd /home/master/software

#rpm -ivh rpm -ivh tengine-2.1.0-0.el6.x86_64.rpm

#vi /opt/config/tengine/vhost/yum.conf

server {
        listen 80;
        server_name yum.ttp.cc;
        location / {
          root /opt/yum;
          index index.htm index.html;
        }
}

#/etc/init.d/rc.tengine start

2、安装createrepo(如果系统有安装这个包,忽略这步)

#yum install createrepo -y

3、自定义repo文件

#cd /etc/yum.repos.d

#vi ttpai.repo

[centos]
name=ttpai centos yum
baseurl=http://yum.ttp.cc/centos/$releasever/os/$basearch/Packages
gpgcheck=0
priority=2

[updates]
name=ttpai centos update
baseurl=http://yum.ttp.cc/centos/$releasever/updates/$basearch/Packages
gpgcheck=0
priority=2

[epel]
name=ttpai epel yum
baseurl=http://yum.ttp.cc/epel/$releasever/$basearch
gpgcheck=0
priority=3

[ttpai]
name=ttpai local yum
baseurl=http://yum.ttp.cc/ttpai/
gpgcheck=0
priority=1

#createrepo -v /opt/yum/

After creating repository, disable or rename the existing repositories.

4、Now update the repository files:

#yum clean all

#yum update

//列出本地仓库的软件包

[root@localhost yum.repos.d]# ls -l /opt/yum/
总用量 275740
#ls -l /opt/yum
drwxrwxr-x 3 master master 4096 8月  31 09:54 centos
drwxrwxr-x 3 master master 4096 8月  31 09:55 epel
drwxr-xr-x 2 root   root   4096 9月   7 14:24 repodata
-rw-rw-r-- 1 master master  304 8月  31 10:45 rsync_mirror.sh
drwxrwxr-x 3 master master 4096 9月   7 11:15 ttpai

二、Client Side Configuration

#cd /etc/yum.repos.d

#vi ttpai.repo

[centos]
name=ttpai centos yum
baseurl=http://yum.ttp.cc/centos/$releasever/os/$basearch/Packages
gpgcheck=0
priority=2

[updates]
name=ttpai centos update
baseurl=http://yum.ttp.cc/centos/$releasever/updates/$basearch/Packages
gpgcheck=0
priority=2

[epel]
name=ttpai epel yum
baseurl=http://yum.ttp.cc/epel/$releasever/$basearch
gpgcheck=0
priority=3

[ttpai]
name=ttpai local yum
baseurl=http://yum.ttp.cc/ttpai/
gpgcheck=0
priority=1

#yum clean all

#yum update

//验证rpm包是否为自定义仓库的包

[root@s03 yum.repos.d]# yum list all |grep tomcat
apache-tomcat-apis.noarch                   0.1-1.el6                    centos
glite-security-trustmanager-tomcat6.noarch  2.5.5-6.el6                  epel   
jakarta-commons-collections-tomcat5.noarch  3.2.1-3.4.el6                centos
jakarta-commons-dbcp-tomcat5.noarch         1.2.1-13.8.el6               centos
jakarta-commons-pool-tomcat5.x86_64         1.3-12.7.el6                 centos
jglobus-ssl-proxies-tomcat.noarch           2.1.0-2.el6                  epel   
tomcat.noarch                               7.0.33-4.el6                 epel   
tomcat.x86_64                               1:6.0.43-0.el6               ttpai  
tomcat-admin-webapps.noarch                 7.0.33-4.el6                 epel   
tomcat-docs-webapp.noarch                   7.0.33-4.el6                 epel   
tomcat-dubbo.x86_64                         7.0.62-0.el6                 ttpai  
tomcat-el-2.2-api.noarch                    7.0.33-4.el6                 epel   
tomcat-javadoc.noarch                       7.0.33-4.el6                 epel   
tomcat-jsp-2.2-api.noarch                   7.0.33-4.el6                 epel   
tomcat-jsvc.noarch                          7.0.33-4.el6                 epel   
tomcat-lib.noarch                           7.0.33-4.el6                 epel   
tomcat-servlet-3.0-api.noarch               7.0.33-4.el6                 epel   
tomcat-webapps.noarch                       7.0.33-4.el6                 epel   
tomcat6.x86_64                              6.0.24-90.el6                centos
tomcat6-admin-webapps.x86_64                6.0.24-90.el6                centos
tomcat6-docs-webapp.x86_64                  6.0.24-90.el6                centos
tomcat6-el-2.1-api.x86_64                   6.0.24-90.el6                centos
tomcat6-javadoc.x86_64                      6.0.24-90.el6                centos
tomcat6-jsp-2.1-api.x86_64                  6.0.24-90.el6                centos
tomcat6-lib.x86_64                          6.0.24-90.el6                centos
tomcat6-servlet-2.5-api.x86_64              6.0.24-90.el6                centos
tomcat6-webapps.x86_64                      6.0.24-90.el6                centos
tomcatjss.noarch                            2.1.0-4.el6                  centos

三、脚本同步源centos和epel

#cat rsync_mirror.sh
#!/bin/sh
#rsync -avz  rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/Packages/* /opt/yum/centos/6/os/x86_64/Packages/
rsync -avz  rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/Packages/* /opt/yum/centos/6/updates/x86_64/Packages/
rsync -avz  rsync://mirrors.ustc.edu.cn/epel/6/* /opt/yum/epel/6                                                                                                                                           

参考链接:http://www.unixmen.com/setup-local-yum-repository-on-centos-rhel-scientific-linux-6-4