腾讯视频/爱奇艺/优酷/外卖 充值4折起
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
gpgkey = file:///etc/pki/rpm-gpg/rpm-gpg-key-rpmforge
gpgcheck = 1
[rpmforge-extras]
name = rhel $releasever - rpmforge.net - extras
baseurl = http://172.25.6.8/rpmforge/$basearch/extras
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/rpm-gpg-key-rpmforge
gpgcheck = 1
[rpmforge-testing]
name = rhel $releasever - rpmforge.net - testing
baseurl = http://172.25.6.8/rpmforge/$basearch/testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/rpm-gpg-key-rpmforge
gpgcheck = 1
6. 检查gpg key是否完整
[root@cc-monitor ~]# ll /etc/pki/rpm-gpg/
total 24
-rw-r--r-- 1 root root 1512 apr 25 2010 rpm-gpg-key-beta
-rw-r--r-- 1 root root 1504 apr 25 2010 rpm-gpg-key-centos-5
-rw-r--r-- 1 root root 1698 apr 15 2012 rpm-gpg-key-epel
如果缺少gpg key可以用rpm导入
#在本地yum源服务器
wget http://apt.sw.be/rpm-gpg-key.dag.txt
mv rpm-gpg-key.dag.txt rpm-gpg-key-rpmforge
#在需要yum安装的客户端执行
rpm --import http://172.25.6.8/rpmforge/rpm-gpg-key-rpmforge
7. 测试三种yum源是否可行
#情况缓存
[root@cc-monitor ~]# yum clean all
loaded plugins: fastestmirror
cleaning up everything
#列出可用的仓库一共有22465的可用包
[root@cc-monitor ~]# yum repolist
repo id repo name status
addons enabled: 0 centos-5 - addons
base enabled: 3,641 centos-5 - base
epel enabled: 7,244 extra packages for enterprise linux 5 - x86_64
extras enabled: 266 centos-5 - extras
rpmforge enabled: 11,158 rhel 5 - rpmforge.net - dag
updates enabled: 156 centos-5 - updates
repolist: 22,465
测试centos标准软件仓库
[root@cc-monitor ~]# yum install nspr nspr-devel
loaded plugins: fastestmirror
determining fastest mirrors
resolving dependencies
--> running transaction check
---> package nspr.i386 0:4.9.2-2.el5_9 set to be updated
---> package nspr.x86_64 0:4.9.2-2.el5_9 set to be updated
---> package nspr-devel.i386 0:4.9.2-2.el5_9 set to be updated
---> package nspr-devel.x86_64 0:4.9.2-2.el5_9 set to be updated
--> finished dependency resolution
测试epel
[root@cc-monitor ~]# yum install nginx
loaded plugins: fastestmirror
loading mirror speeds from cached hostfile
setting up install process
resolving dependencies
--> running transaction check
---> package nginx.x86_64 0:0.8.55-2.el5 set to be updated
--> processing dependency: libxslt.so.1()(64bit) for package: nginx
--> processing dependency: libgd.so.2()(64bit) for package: nginx
--> processing dependency: libexslt.so.0()(64bit) for package: nginx
--> processing dependency: libgeoip.so.1()(64bit) for package: nginx
--> running transaction check
---> package geoip.x86_64 0:1.4.8-1.el5 set to be updated
---> package gd.x86_64 0:2.0.33-9.4.el5_4.2 set to be updated
--> processing dependency: pkgconfig for package: gd
--> processing dependency: libxpm.so.4()(64bit) for package: gd
---> package libxslt.x86_64 0:1.1.17-4.el5_8.3 set to be updated
--> running transaction check
---> package libxpm.x86_64 0:3.5.5-3 set to be updated
---> package pkgconfig.x86_64 1:0.21-2.el5 set to be updated
--> finished dependency resolution
测试rpmforge
[root@cc-monitor ~]# yum install htop
loaded plugins: fastestmirror
loading mirror speeds from cached hostfile
rpmforge
setting up install process
resolving dependencies
--> running transaction check
---> package htop.x86_64 0:1.0.2-1.el5.rf set to be updated
--> finished dependency resolution