Creating A Local Yum Repository on CentOS 5.x
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:
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
#!/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