APT/YUM Server

出自Centos

跳转到: 导航, 搜索

yum服务器设置 完整的centos public mirror地址: http://www.centos.org/modules/tinycontent/index.php?id=13

离大陆最近的香港镜像ftp服务器: ftp://ftp.hostrino.com/pub/centos/

nohup copydir -v ftp://mirror.vpshosting.com.hk/pub/linux/centos/5.2/updates/i386/RPMS/ /home/disk1/yum/updates/ > myout.file 2>&1 &

需要的服务器组件:

yum
yum-updatesd
yum-utils
createrepo
[root@xingke ~]# yum -y install yum-utils
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * rpmforge: fr2.rpmfind.net
 * base: mirror.be10.com
 * updates: ftp2.tnc.edu.tw
 * addons: ftp2.tnc.edu.tw
 * extras: ftp2.tnc.edu.tw
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.10-9.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 yum-utils               noarch     1.1.10-9.el5.centos  base               59 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 59 k
Downloading Packages:
(1/1): yum-utils-1.1.10-9 100% |=========================|  59 kB    00:03
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: yum-utils                    ######################### [1/1]

Installed: yum-utils.noarch 0:1.1.10-9.el5.centos
Complete!

[root@xingke ~]# yum -y install createrepo
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * rpmforge: fr2.rpmfind.net
 * base: mirror.be10.com
 * updates: ftp2.tnc.edu.tw
 * addons: ftp2.tnc.edu.tw
 * extras: ftp2.tnc.edu.tw
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.4.11-3.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 createrepo              noarch     0.4.11-3.el5     base               59 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 59 k
Downloading Packages:
(1/1): createrepo-0.4.11- 100% |=========================|  59 kB    00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: createrepo                   ######################### [1/1]

Installed: createrepo.noarch 0:0.4.11-3.el5
Complete!
[root@xingke ~]#mount -o loop CentOS-5.2-i386-bin-DVD.iso /home/nfs/
[root@xingke CentOS]# cd /home/nfs/CentOS
[root@xingke CentOS]# cp * /home/disk1/yum/base/

[root@xingke base]# createrepo /home/disk1/yum/base/
2458/2458 - notify-python-0.1.0-3.fc6.i386.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[root@xingke base]#
base里面共2458个rpm包,接下来屏幕就会开始刷了起来,我这里的共2千多个包,所以要等它一段时间。完成后,其实你的依赖性报告已经写在了repodata这个目录里了。呵呵
[root@xingke base]#rsync -avuz centos.mirrors.firstnetcom.com::centos/5.2/updates/i386/RPMS/ /home/yum/


[编辑] 创建CentOS Mirror服务器脚本

具体方法如下:创建一个镜像脚本centos-mirror.sh

代码

#!/bin/sh

export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

rsync="/usr/bin/rsync -aqzH --delete --delay-updates"

mirror=rsync://mirrors.kernel.org/centos

verlist="5 4"
archlist="i386 SRPMS"
baselist="os updates addons extras centosplus contrib fasttrack"
local=/home/centos

for ver in $verlist
do
for arch in $archlist
do
for base in $baselist
do
if [[ $ver = '4' ]] && [[ $base = 'fasttrack' ]]; then
continue
fi

if [[ $ver = '5' ]] && [[ $base = 'contrib' ]]; then
continue
fi

remote=$mirror/$ver/$base/$arch/
mkdir -p $local/$ver/$base/$arch
$rsync $remote $local/$ver/$base/$arch/
done
done
done 

设置crontab每6小时更新一次: 0 0-23/6 * * * /root/centos-mirror.sh

个人工具