CentOS下建立本地YUM源并自动更新

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

(0)

相关推荐

  • Centos6.4建立本地yum源

    对于Linux系统如果无网络也想安装一些软件的话,最好的选择就是自己搭建一个本地的yum源 操作方法 01 放入Centos6.4的镜像光盘或找到镜像文件 mount –o loop –t iso96 ...

  • Redhat linux本地yum源的配置教程

    相信对RedHat Linux或CentOS比较熟悉的人,应该是比较了解yum源的,它比普通的rpm包安装,要方便的多,为何呢?因为它能顺利的解决rpm包之间的依赖关系。你要是根据rpm包之间的依赖关 ...

  • 如何配置Centos 6.5 的yum源?

    无论是使用哪一个版本的Linux都会用到一个源安装软件库,方便软件的安装与卸载,下面我与大家分享一下如何配置Centos 6.5 的yum源。 1、首先我们根据自己使用的系统找到对应的软件库,例如我服 ...

  • centos7如何配置本地yum源

    最近在使用虚拟机时遇到一些麻烦,因为公司内部有网络管理,所以vm连接不上外网,yum无法安装软件,怎么解决呢?–使用iso做本地yum源,可以解决大部份的包安装. vm安装的是centos7. 1.挂 ...

  • linux如何添加本地yum源

    本文主要介绍linux服务器如何在没有网络的情况下依然可以使用yum命令安装软件,主要是通过添加本地yum源,来保证可以正常使用yum命令. 具体linux基本命令不在本文说明,请自行查找. 操作方法 ...

  • linux配置本地yum源方法

    最近做一个项目,机房不能上外网,等centos6.5安装完成之后发现没有安装gcc等基础包.最开始尝试着通过rpm包的方法进行安装,包与包之间的依赖关系折腾了我近半个小时.无奈之下只好通过搭建本地yu ...

  • Word中建立域后怎样进行自动更新.锁定及其他操作?

    宏.域,可以在Word中实现自动化操作,本节要为大家讲解的是建立域后怎样进行自动更新,锁定,及其他操作,由于这个操作比较频繁,所以建议大家切记,熟练.大概步骤就是插入域,在对话框中类别下选择相应的分类 ...

  • RHCE心得3 基于VSFTP的本地YUM源及光盘YUM源搭建步骤分享

    一、yum环境的本地源搭建(基于VSFTP): 1)安装vsftp; ****************************************** [root@service ~]# moun ...

  • CentOS配置163的yum源

    CentOS系统自带的YUM源更新太慢,所以更新使用了163的YUM源 操作方法 01 下载repo文件 wget http://mirrors.163.com/.help/CentOS6-Base- ...