Facebook Twitter Gplus RSS
 
 
Home » CentOS » Creating A Local Yum Repository on CentOS 5.x
formats

Creating A Local Yum Repository on CentOS 5.x

Published on March 14th, 2009

centosReducing the costs of I.T without reducing the functionally of your systems is one of the major obstacles to overcome. One of these costs is bandwidth, especially in South Africa.

One of the first bandwidth saving tips any organization should know is the importance of creating a local YUM repository on your LAN. Not only do you decrease the time it takes to download and install updates, you also decrease bandwidth usage. This saving will definitely please the suites of any organization.

This How To show’s you a simple yet effective way of setting up your local YUM server and client.

TIP: Distribute your YUM configuration via your Puppet Master

Preliminary Note:

We are using two empty CentOS 5.2 servers in this tutorial:

* server1.example.co.za (IP 10.0.0.100): YUM Repo server
* server2.example.co.za (IP 10.0.0.102): YUM client

Configure YUM repo server as follows:

Create the following Directories:

# mkdir -p /var/www/html/centos/5.3/os/i386
# mkdir -p /var/www/html/centos/5.3/updates/i386
# mkdir -p /var/www/html/centos/5.3/os/x86_64
# mkdir -p /var/www/html/centos/5.3/updates/x86_64
# mkdir -p /var/www/html/centos/5.2/os/i386
# mkdir -p /var/www/html/centos/5.2/updates/i386
# mkdir -p /var/www/html/centos/5.2/os/x86_64
# mkdir -p /var/www/html/centos/5.2/updates/x86_64
# mkdir -p /var/www/html/centos/5/os/i386
# mkdir -p /var/www/html/centos/5/updates/i386
# mkdir -p /var/www/html/centos/5/os/x86_64
# mkdir -p /var/www/html/centos/5/updates/x86_64

Create a bash script that will rsync your local YUM Repo server with your local YUM mirror (Internet Solutions – ftp.is.co.za).
CentOS Mirror list – http://www.centos.org/modules/tinycontent/index.php?id=30

# vi yum-repo-update.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
 
rsync="rsync -avrt --bwlimit=256"
 
mirror=ftp.is.co.za::IS-Mirror/centos
 
verlist="5 5.2 5.3"
archlist="i386 x86_64"
baselist="os updates"
local=/var/www/html/centos/
 
for ver in $verlist
do
 for arch in $archlist
 do
  for base in $baselist
  do
    remote=$mirror/$ver/$base/$arch/
    $rsync $remote $local/$ver/$base/$arch/
  done
 done
done

# chmod 755 yum-repo-update.sh

Add the bash script to your crontab to update your local repository every night (01H00 in this case)

# crontab -e

1
2
3
4
5
6
7
8
9
10
#       minute (0-59),
#       |       hour (0-23),
#       |       |       day of the month (1-31),
#       |       |       |       month of the year (1-12),
#       |       |       |       |       day of the week (0-6 with 0=Sunday).
#       |       |       |       |       |       commands
# -----------[ cron jobs  ]------------ #
 
# Update Local YUM repo update from ftp.is.co.za
		0 	  1 	  * 	  * 	  * 	   /path/to/yum-repo-update.sh

Configure YUM client servers as follows:

Rename all existing yum repositories from *.repo to *.old

# vi /etc/yum.repos.d/localCentOS-Base.repo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[base]
name=CentOS-$releasever - Base
baseurl=http://server1.example.co.za/centos/$releasever/os/$basearch/
gpgcheck=0
 
[update]
name=CentOS-$releasever - Updates
baseurl=http://server1.example.co.za/centos/$releasever/updates/$basearch/
gpgcheck=0
 
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://server1.example.co.za/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=0
enabled=0

Test your setup by running a yum update on your client machine.

# yum update

Loading “fastestmirror” plugin
Loading mirror speeds from cached hostfile
* update: server1.example.co.za
* base: server1.example.co.za

 
  • Pingback: Installing XEN on CentOS 5.x | George Rushby dot com

  • Pingback: How to Set up Network Bonding with CentOS 5.x | George Rushby dot com

  • Pingback: Adding CentOS 5.3 to Local YUM Repository | George Rushby dot com

  • Anu V Das

    This document is really cool.I was able to create a local repo

    Thanks a bunch dude!

  • Douglas

    Very nicely structured doc, easy to follow. Great site!

  • AndrewBoldman

    da best. Keep it going! Thank you

  • http://www.3am.co.za Riaan nolan

    very nicely done ! have to agree :)

    ps. gentoo rocks !

  • Bob

    Could you explain the syntax where you name the mirror variable?

    mirror=ftp.is.co.za::IS-Mirror/centos

    Say for example we would use:
    ftp://mirrors.usc.edu/pub/linux/distributions/centos/

  • http://www.how2centos.com George

    You need to specify a RSYNC mirror, the link you supplied is for a FTP mirror.

    Presuming you’re using the University of Southern California mirror your syntax would be:

    mirror=mirrors.usc.edu::centos

  • Paul

    I like your rsync script but made one change for my use. Having 5 under the versions makes the script sync the files a second time and not create the links which are at a root level. I thus took the 5 out of the verlist and added this code

    basever=”5″
    # Sync the symlinks to the base version directory
    for bver in $basever
    do
    $rsync $mirror/$bver/ $local/$bver
    done

  • Pingback: Adding #CentOS 5.4 to Local #YUM Repository | How 2 #CentOS

  • Pingback: Adding #CentOS 5.3 to Local #YUM Repository | How 2 #CentOS

  • Greg

    Hi I'm trying to follow your guide but I'm having this error…

    rsync: failed to connect to mirror.pscigrid.gov.ph: Connection timed out (110)
    rsync error: error in socket IO (code 10) at clientserver.c(107) [receiver=2.6.8]

    I'm trying to change mirror link to ftp://mirror.pscigrid.gov.ph/centos/ this mirror is the nearest repo to my country. how can I make it work please help thanks a lot…

  • How2CentOS

    The script only works with RSYNC repositories. What country you from so that I can help you amend your script?

  • Pingback: Installing #XEN on #CentOS 5.x | How 2 #CentOS

  • Pingback: How to Set up #Network #Bonding with #CentOS 5.x | How 2 #CentOS

  • http://mymcp.blogspot.com Steve Lippert

    Instead of running each mkdir command like you do you can run just one command:
    # mkdir -pv {5,5.1,5.2,5.3,5.4,5.5}/{os,updates}/{i386,x86_64}

    Which outputs:

    mkdir: created directory `5.4'
    mkdir: created directory `5/os'
    mkdir: created directory `5/os/i386'
    mkdir: created directory `5/os/x86_64'
    mkdir: created directory `5/updates'
    mkdir: created directory `5/updates/i386'
    mkdir: created directory `5/updates/x86_64'

    and will continue on to create all of the version directories you require.
    Just run this same command each time there is a new version and you are all set for your update script.

    Also a big thank you for concise working instructions. The other instructions on the internet are not complete and missing a few steps.

  • How2CentOS

    Thanks for the support and updated command Steve, I will definitely incorporate it in my next Blog Post.

  • ledpepper

    Hi, thanks for the great post!

    How big is the IS/saix mirror if I were to rsync? I don’t need a lot of the rpm’s included in the mirror. Is this scenario possible:

    I install Centos 5.5 from ISO.
    (yum update usually requires 300mb download.)
    use yum-downloadonly –downloaddir=/var/www/http/repos/

    Thanks again

  • Anonymous

    The download mirror is roughly about 16GB but that’s for both 32 and 64bit.

    What you can do is copy the RPM’s from the disk to the local yum repo and then RSYNC the remaining 300MB

  • http://www.facebook.com/mhammett Mike Hammett

    I modified this to support all CentOS 5 installs, vs. changing to just the newer versions.

    However, I have tried to change to a more local RSYNC mirror, but the only line I can get to work in mirror is exactly what you have. I will admit that I don’t understand the ::IS-Mirror portion.

  • Kusanagiyang

    hi greg,
    i hope you have resolved your issue by now.
    just in case, the phillipine mirror doesn’t seem to support rsync protocol.
    pick another from the list
    http://www.centos.org/modules/tinycontent/index.php?id=32
    good luck

© [How2CentOS]
credit