免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1875 | 回复: 0
打印 上一主题 下一主题

CentOS5构建本地yum仓库(同步网站) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-19 02:04 |只看该作者 |倒序浏览

                                                 
   
为CentOS5构建本地yum仓库 由Linux系统中文网(Linux521.com)编辑收集整理,除Linux521注明原创文章外,其版权归原作者所有。如果您在学习中遇到问题欢迎在下面的评论中留言,我们会尽全力解答您的问题。;项目中大量使用CentOS5作为运行平台,测试需要经常安装系统,每次要升级的文件越来越多,构建内部仓库一来方便安装,二来方便升级。。。

http://www.linux521.com/2009/system/200907/7499.html


[服务端]
创建基本仓库,并copy DVD或者CD文件(减少网络下载量)
Copy the RPMs from the CDs/DVD to /var/www/html/centos/5/base.
1. mount -o loop,ro CentOS-xxxxx.iso /mnt
2. cp -r /mnt /var/www/html/centos/5/base
同步远端仓库
3./usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5/os/i386/ /var/www/html/centos/5/os/i386/


同步update仓库
例子:
/usr/bin/rsync -avrt rsync://rsync.muug.mb.ca/centos/5/updates/i386/ /opt/repos/yum/centos/5/updates/i386/
镜像在这里的列表中选中快的
http://www.centos.org/modules/tinycontent/index.php?id=30
客户端使用仓库
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.xx.xx/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[update]
name=CentOS-$releasever - Updates
baseurl=http://192.168.xx.xx/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=
http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5































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





http://www.linuxidc.com/Linux/2009-08/21317p2.htm



Fedora
11推出后,Linux在桌面上的易用性大为提高,具备在办公/开发
环境
部署
的可能性。
但才发布几天,yum update要下载的
升级
包竟然接近200M, 没办法,这是开源软件无法避免的,补丁频繁肯定。
为了避免内网机器重复下载相同文件,可以创建一个升级仓库内网私用。
-
[服务端仓库创建和配置]
1.安装创建仓库的工具
yum install createrepo
   
   
        
            
            

            
        
   
2.创建目录结构
mkdir -p /xxxxxxx/repos/yum/
Fedora
/base/11/i386
mkdir -p /xxxxxxx/repos/yum/
Fedora
/updates/11/i386
注:/xxxxxxx/是任意选定的文件系统路径
3.复制DVD的文件到到base目录
mount -o loop,ro
Fedora
11-i386-DVD.iso  /mnt/iso
cp -v /mnt/iso/Packages/*  /xxxxxxx/repos/yum/
Fedora
/base/11/i386
umount /mnt/iso
4.DVD光盘只包含基本的安装包集合,如果需要
所有
安装包,先执行下面:(不同镜像任选其一)
rsync -avrt –progress  rsync://ftp.jaist.ac.jp/pub/Linux/
Fedora
/releases/11/Everything/i386/os/Packages/  /xxxxxxx/repos/yum/fedora/base/11/i386
rsync -avrt  –progress  rsync://mirror.anl.gov/
Fedora
/linux/releases/11/Everything/i386/os/Packages/  /xxxxxxx/repos/yum/fedora/base/11/i386
注1:rsync语法要求严格,目录同步不能缺少源路径最后的”/”
注2:请在
http://mirrors.fedoraproject.org/publiclist/Fedora/11/
页面中中找一个合用的rsync镜像
5.创建仓库所需要的数据结构文件
createrepo /xxxxxxx/repos/yum/
Fedora
/base/11/i386
会生成/xxxxxxx/repos/yum/
Fedora
/base/11/i386/repodata目录,里面包含若干xml和gz文件
6.同步updates目录
rsync -avrt –progress  rsync://ftp.jaist.ac.jp/pub/Linux/
Fedora
/updates/11/i386/  –exclude=debug/ /xxxxxxx/repos/yum/fedora/updates/11/i386
7.生成cron任务定期自动更新updates
crontab -e (每天晚上2时40分更新)
40 2 * * * /usr/bin/rsync -avrt  rsync://mirror.anl.gov/
Fedora
/linux/updates/8/i386/  –exclude=debug/ /xxxxxxx/repos/yum/fedora/updates/11/i386
8.配置httpd供访问
基本上就是生成别名
www.adbrite.cc
或命名虚拟主机方式进行访问了
下面是基于名称的虚拟主机的配置方式
cat  000-default
NameVirtualHost *:80
DocumentRoot “/var/www/html”
Options FollowSymLinks
AllowOverride None
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ServerAdmin admin@localdomain
DocumentRoot /xxxxx/repos
ServerName updates.domain.net
DirectoryIndex index.html
LogLevel debug
ErrorLog logs/updates.domain.net-error_log
CustomLog  logs/updates.domain.net-access_log common
  
Options Indexes
Order allow,deny
allow from all


[客户端配置]
touch  /etc/yum.repos.d/local.repos
vi /etc/yum.repos.d/local.repos
内容如下:
[base-local]
name=
Fedora
  $releasever -  $basearch
failovermethod=priority
baseurl=http://updates.domain.net/yum/
Fedora
/base/$releasever/$basearch
   
   
        
            
            

            
        
   
enabled=1
gpgcheck=0
[updates-local]
name=
Fedora
  $releasever - $basearch -  Updates
failovermethod=priority
baseurl=http://updates.domain.net/yum/
Fedora
/updates/$releasever/$basearch/
enabled=1
gpgcheck=0
最后把原来的repos文件中base和updates有关的改为enabled=0
然后在客户端执行yum  update可以体验本地飞速update~~…

为CentOS5构建本地yum仓库
项目中大量
使用
CentOS5作为运行平台,
www.britepic.org
测试需要经常安装系统,每次要升级的文件越来越多,构建内部仓库一来方便安装,二来方便升级。。。

[
服务
端]
创建基本仓库,并copy  DVD或者CD文件(减少网络下载量)
Copy  the RPMs from the CDs/DVD to /var/www/html/centos/5/base.
1.  mount -o loop,ro CentOS-xxxxx.iso /mnt
2. cp -r /mnt  /var/www/html/centos/5/base
同步远端仓库
3./usr/bin/rsync  -avrt –delete rsync://rsync.muug.mb.ca/centos/5/os/i386/  /var/www/html/centos/5/os/i386/
同步update仓库
例子:
/usr/bin/rsync  -avrt rsync://rsync.muug.mb.ca/centos/5/updates/i386/  /opt/repos/yum/centos/5/updates/i386/
镜像在这里的列表中选中快的

http://www.centos.org/modules/tinycontent/index.php?id=30

客户端使用仓库
[base]
name=CentOS-$releasever -  Base
baseurl=http://192.168.xx.xx/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released  updates
[update]
name=CentOS-$releasever -  Updates
baseurl=http://192.168.xx.xx/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
























http://hi.baidu.com/suantop/blog/item/7f82e9b549d2a6c436d3ca99.html





在公网的服务器中找一个apache发布一个目录
例如/var/www/html/centos
找一台速度较快的带rsync服务的镜像网站
http://centos.ustc.edu.cn/centos/5.4
同步需要的软件到web目录下,例如:(由于系统的32位的,我屏蔽了x86_64目录,debug的东西也用不到,所以也屏蔽了debug,还需要有屏蔽,自己根据需要来,--exclude支持正则的 :))
# rsync -avrt rsync://centos.ustc.edu.cn/centos/5.4/
--exclude=debug/ --exclude=x86_64/ --exclude=isos/
/var/www/html/centos/5.4/
公网也很快 所以可以全部下载只是不要x86_64
http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
# rsync -avrt rsync://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5 /var/www/html/centos5.4/
然后到
/etc/yum.repos.d/
# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
# cp CentOS-Base.repo.5 CentOS-Base.repo
把里面内容的baseurl替换为自己的
然后就可以客户端升级了
wget http://mirror.centos.org/centos/5/os/i386/CentOS/centos-release-5-4.el5.centos.1.i386.rpm
wget http://mirror.centos.org/centos/5/os/i386/CentOS/centos-release-notes-5.4-4.i386.rpm
http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/centos-release-5-4.el5.centos.1.i386.rpm
http://centos.ustc.edu.cn/centos/5.4/os/i386/CentOS/centos-release-5-4.el5.centos.1.i386.rpm
在公网的服务器中找一个apache发布一个目录
下面尝试下载一个文件
rsync -avrt rsync://centos.ustc.edu.cn/centos/5.4/os/i386/CentOS/centos-release-5-4.el5.centos.1.i386.rpm /var/www/html
-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-v, --verbose 详细模式输出
-r, --recursive 对子目录以递归模式处理
-t, --times 保持文件时间信息
列远程机的文件列表。这类似于rsync传输,不过只要在命令中省略掉本地机信息即可。如:rsync -v rsync://172.16.78.192/www
[root@mail html]# rsync -avrt rsync://mirror.averse.net/centos/RPM-GPG-KEY-CentOS-5 /var/www/html/
[root@mail html]# rsync -avrt
rsync://centos.ustc.edu.cn/centos/5.4/os/i386/CentOS/centos-release-5-4.el5.centos.1.i386.rpm
/var/www/html/
http://192.168.1.19/RPM-GPG-KEY-CentOS-5
http://centos.ustc.edu.cn/CentOS-Base.repo.5
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=http://centos.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://centos.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://centos.ustc.edu.cn/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://centos.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://centos.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5




























http://www.hao32.com/webserver/315.html

架设本地的

yum服务器

(centos)

19. 01.
1.事实上,很多时候会用到本地的yum服务器,不仅仅是因为国内的镜像少,速度慢,不连线到公网的机器有时候也有这个必要
2.本文是以实际环境为例,简单的说明一下配置情况,办法很土,呵呵
3.环境(CentOS 5 32位)
一台web服务器,在公网,内网ip是192.168.1.7
另外一台db服务器只在内网,ip是192.168.1.8
4.找一台速度较快的带rsync服务的镜像网站
从这里找:http://www.centos.org/modules/tinycontent/index.php?id=13
我选了新加坡的一个:rsync://mirror.averse.net/centos/5.2/ 具体根据自己的网络情况而定
5.192.168.1.7正好是web服务器,直接就可以利用,找一个web目录,例如:/www/wwwroot/yum 随便绑定个域名,例如:www.yum.com、
# mkdir -p /www/wwwroot/yum
在192.168.1.8上/etc/hosts里指定www.yum.com到192.168.1.7,这样访问www.yum.com就可以直接访问此目录
6.同步需要的软件到web目录下,例如:(由于系统的32位的,我屏蔽了x86_64目录,debug的东西也用不到,所以也屏蔽了debug,还需要有屏蔽,自己根据需要来,--exclude支持正则的 :))
# rsync -avrt rsync://mirror.averse.net/centos/5.2/ --exclude=debug/
--exclude=x86_64/ --exclude=isos/ /www/wwwroot/yum/centos/5/
# rsync -avrt rsync://mirror.averse.net/centos/RPM-GPG-KEY-CentOS-5 /www/wwwroot/yum/centos/
等待完成……
完成了之后,可以做一个计划任务,隔段时间更新一下,
7.在192.168.1.8上配置yum,打开/etc/yum.repos.d/CentOS-Base.repo
替换内容如下:
[base]
name=CentOS-5 - Base
baseurl=http://www.yum.com/yum/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#released updates
[update]
name=CentOS-5 - Updates
baseurl=http://www.yum.com/yum/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
baseurl=http://www.yum.com/yum/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
baseurl=http://www.yum.com/yum/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus
baseurl=http://www.yum.com/yum/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib
baseurl=http://www.yum.com/yum/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
#packages in testing
[testing]
name=CentOS-5 - Testing
baseurl=http://www.yum.com/yum/centos/5/testing/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://www.yum.com/yum/centos/RPM-GPG-KEY-CentOS-5
8.在内网192.168.1.8上就可以正常使用yum来安装或者升级软件啦































































/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/updates/i386/ /opt/CentOS/updates/


/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/addons/i386/ /opt/CentOS/addons
/


/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/centosplus/i386/ /opt/CentOS/centosplus/



/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/extras/i386/ /opt/CentOS/extras/


/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/fasttrack/i386/ /opt/CentOS/fasttrack/


/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/os/i386/i386/ /opt/CentOS/os/


/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/updates/i386/ /opt/CentOS/updates/

               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/108430/showart_2125400.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP