Reducing 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:
I’m 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
#!/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
# 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
[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
Related posts:







[...] Install a CentOS 32 bit Virtual Machine using virt-install and your local YUM repository [...]
[...] using the CentOS 5.2 YUM server in this [...]
[...] Adding CentOS 5.3 to Local YUM Repository Filed under: System Administration — George @ 8:13 am Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Powered by WP Greet BoxCentOS 5.3 has just been released and that means it’s time to update our Local CentOS 5.x YUM repo. [...]
This document is really cool.I was able to create a local repo
Thanks a bunch dude!
Very nicely structured doc, easy to follow. Great site!
da best. Keep it going! Thank you
very nicely done ! have to agree
ps. gentoo rocks !
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/
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
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
[...] the release of RHEL 5.4, CentOS 5.4 has just hit the CentOS mirrors. Time to update the Local CentOS YUM repository [...]
[...] Please read creating a Local CentOS YUM repository on CentOS 5.x before [...]
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…
The script only works with RSYNC repositories. What country you from so that I can help you amend your script?
[...] Install a CentOS 32 bit Virtual Machine using virt-install and your local YUM repository [...]
[...] using the CentOS 5.2 YUM server in this [...]
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.
Thanks for the support and updated command Steve, I will definitely incorporate it in my next Blog Post.