1. 盡管有很多的免費鏡像提供yum源服務,但是還是有必要建立自己的yum服務器,主要出於以下幾點考慮:
l 網絡速度:訪問互聯網可能比較慢
l 節省帶寬:如果有大量的服務器,架設自己的yum源可以有效節省互聯網帶寬
l 聯網限制:對於有些內網服務器,不能連接到互聯網
l 對於RHEL(Redhat Enterprise Linux),需要購買服務
l 便於發布自己開發的rpm包
2. 找到適合你的站點的yum同步源,主要是CentOS標准軟件倉庫、epel、以及rpmforge
CentOS標准倉庫選擇列表
Asian:
http://www.centos.org/modules/tinycontent/index.php?id=32
North American
http://www.centos.org/modules/tinycontent/index.php?id=30
Epel源選擇列表
http://mirrors.fedoraproject.org/publiclist/EPEL/
Rpmforge源
http://apt.sw.be/
要選盡量離你的local服務器近的地區,並支持RSYNC,方便更新同步
我選擇的是Linux Kernel Archives
CentOS標准軟件倉庫
rsync://mirrors.kernel.org/centos
Epel源
rsync://mirrors.kernel.org/fedora-epel
Rpmforge源
rsync://ftp-stud.fht-esslingen.de/dag
rsync://mirror.cpsc.ucalgary.ca/dag
3. 編寫同步腳本,根據需求進行自動同步
[root@cc-system-manager1 bin]# vi update_yum_source.sh
#!/bin/bash
#==========================================
# Program : update_yum_source.sh
# Info : 定期同步官方 yum 源到本機
# Version : 2013.03.05 First Release
#==========================================
Date=`date +%Y%m%d`
LogFile="/tmp/update_yum_source.log"
CentOSTrunkVer="5"
CentOSCurrentVer="5.9"
RsyncBin="/usr/bin/rsync"
RsyncPerm="-avrt --delete --exclude=debug/ --exclude=isos/"
CentOS_Trunk_Ver_Path="/servers/yum_update/$CentOSTrunkVer"
CentOS_Current_Ver_Path="/servers/yum_update/$CentOSCurrentVer"
YumSiteList="rsync://mirrors.kernel.org/centos"
echo "---- $Date `date +%T` Begin ----" >>$LogFile
# centos 5
$RsyncBin $RsyncPerm $YumSiteList/$CentOSTrunkVer/
$CentOS_Trunk_Ver_Path/ >> $LogFile
# centos 5.9
$RsyncBin $RsyncPerm $YumSiteList/$CentOSCurrentVer/
$CentOS_Current_Ver_Path/ >> $LogFile
echo "---- $Date `date +%T` End ----" >> $LogFile
[root@cc-system-manager1 bin]# vi update_epel_source.sh
#!/bin/bash
#==========================================
# Program : update_epel_source.sh
# Info : 定期同步官方 epel 源到本機
# Version : 2013.03.05 First Release
#==========================================
Date=`date +%Y%m%d`
LogFile="/tmp/update_epel_source.log"
RsyncBin="/usr/bin/rsync"
RsyncPerm="-avrt --delete --exclude=4/ --exclude=4AS/ --exclude=4ES/ --exclude=4WS/ --exclude=6/ --exclude=testing/"
#============ epel ==============
epelSite="rsync://mirrors.kernel.org/fedora-epel"
epelLocalPath="/servers/epel"
echo "---- $Date `date +%T` Begin ----" >>$LogFile
# epel
$RsyncBin $RsyncPerm $epelSite $epelLocalPath >> $LogFile
echo "---- $Date `date +%T` End ----" >> $LogFile
[root@cc-system-manager1 bin]# vi update_rpmforge_socure.sh
#!/bin/bash
#==========================================
# Program : update_rpmforge_source.sh
# Info : 定期同步官方 rpmforge 源到本機
# Version : 2013.03.05 First Release
#==========================================
Date=`date +%Y%m%d`
LogFile="/tmp/update_rpmforge_source.log"
RsyncBin="/usr/bin/rsync"
RsyncPerm="-avrt --delete --exclude=i386/ --exclude=ppc/ --exclude=source/"
# rpmforge
#rpmforgeSite="rsync://apt.sw.be/redhat/el5/en/"
rpmforgeSite="rsync://ftp-stud.fht-esslingen.de/dag/redhat/el5/en/"
rpmforgeLocalPath="/servers/rpmforge"
echo "---- $Date `date +%T` Begin ----" >>$LogFile
# rpmforge
$RsyncBin $RsyncPerm $rpmforgeSite $rpmforgeLocalPath >> $LogFile
echo "---- $Date `date +%T` End ----" >> $LogFile
4. 在apache的配置文件裡做好相應的軟連接或者修改主目錄指向
cd /var/www/html/
ln -s /servers/yum_update/ yum
ln -s /servers/epel epel
ln -s /servers/rpmforge rpmforge
5. 分別創建3個repo的配置文件,指向本地源所在的服務器,注意目錄
[root@cc-monitor yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://172.25.6.8/yum/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://172.25.6.8/yum/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://172.25.6.8/yum/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://172.25.6.8/yum/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://172.25.6.8/yum/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://172.25.6.8/yum/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[root@cc-monitor yum.repos.d]# vi epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
baseurl=http://172.25.6.8/epel/5/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
baseurl=http://172.25.6.8/epel/5/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
baseurl=http://172.25.6.8/epel/5/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
[root@cc-monitor yum.repos.d]# vi rpmforge.repo
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://172.25.6.8/rpmforge/$basearch/rpmforge
enabled = 1
protect = 0