Creating A Local Yum Repository on CentOS 5.x

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:

  • (IP YUM Repo server
  • (IP 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 –
CentOS Mirror list –

# vi

rsync="rsync -avrt --bwlimit=256"

verlist="5 5.2 5.3"
archlist="i386 x86_64"
baselist="os updates"

for ver in $verlist
 for arch in $archlist
  for base in $baselist
    $rsync $remote $local/$ver/$base/$arch/
# chmod 755

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

# crontab -e
#       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
        0     1       *       *       *        /path/to/

Configure YUM client servers as follows:

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

# vi /etc/yum.repos.d/localCentOS-Base.repo
name=CentOS-$releasever - Base

name=CentOS-$releasever - Updates

name=CentOS-$releasever - Extras

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

# yum update

Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * update:
 * base: