DISCLAIMER: This how-to does not seem to work for 5.3 and up. Actually, the repo updates did not seem to work properly. I will test and try to update this document during 2010, time and ressources permitting.YUM REPOSITORY MIRROR SETUP GUIDE FOR CENTOS 5



HOW I BUILT A CENTOS 5.2 YUM REPOSITORY AND LIVED TO TELL THE TALE



System Requirements:

A working CentOS 5.2 server with Apache, the createrepo package, a set of the CentOS 5.2 ISO images (install CDs or the single install DVD), a working broadband internet connection. Since my server farm lives in my basement and that I like working from a bright, naturally lit room, I used one of my Macs with the Transmit application for some of the dirty work, but a second computer is entirely optional.

Note: I am a bit crazy, but not crazy enough yet to test this on all the various RedHat based "flavors" of linux. So if you wish to try this on your own box but don't run CentOS 5.2, your milleage may vary. The process should be pretty identical in Redhat and Fedorah Core. By the way, this example is based on the 32 bit environment, but you can pretty much reproduce it with the other environments. If I end up with a 64 bit server here one of these days, I’ll probably deploy the 64 bit repos as well...

THE ACTUAL RECIPE


STEP 1


The first step is to create the repository directories within your web server's structure. Open a shell on the system (either locally or via ssh from a remote terminal, assuming you have ssh running and accepting connections), then, with root privileges, run the following command:

mkdir -pv /var/www/html/CentOS/5.2/{iso,os,updates}

This will create the centos iso, os (base) and updates directories, where the mirrored packages will be copied to - and served from. Note: as this server is going to be running for the internal network only, I didn’t modify my Apache config, but you should consider creating the directories elsewhere and either customize your httpd.conf file accordingly or create a vhost entry with the proper settings. Like I said earlier, I am lazy. ;-)


STEP 2


After you've created the directories , you'll need to copy all the RPMs from the /CentOS directory on your install CDs/DVD to the /var/www/html/CentOS/5.2/os directory. You will also copy the iso disk images to the iso directory. I am intellectually lazy (read: when I can, I use GUI tools), so I used Transmit (my favorite SFTP tool on OS X, it's commercial but you can use University of Michigan's Fugu) to copy all files from a copy of the CentOS 5.2 DVD ISO I downloaded from a CentOS mirror (or, the longer road, mount each of the six CD isos and copy the files from each). Windows users can use WinSCP or any other SFTP/SCP client. So:

1. Establish an SFTP connection to your target mirror server using the root account/password.
2. Copy all the RPM files from the /CentOS directory on the mounted DVD to the /var/www/html/CentOS/5.2/os directory on your target mirror server.
3. Copy the iso (s) of your install DVD or CDs to the /var/www/html/CentOS/5.2/iso directory

You could also mount the images, copy the contents, then unmount them. Whatever works for you is fine.

STEP 3


When that is completed, time to populate the update repository. At this point, we need to get the rpm files from the update repository using rsync. You'll have to check the list at:

http://www.centos.org/modules/tinycontent/index.php?id=13

Here is the command you will run to get the updated packages (you can replace the mirrors.url part of the command with the rsync mirror you want from the list mentionned above):

rsync -avrt rsync://mirrors.url/centos/5.2/updates/i386 --exclude=debug/ /var/www/html/CentOS/5.2/updates/

Here is a sample shot of the command running (I’ve replaced the real url with the example above in the cut and paste text, it would defeat the purpose if everyone used the same mirror for their updates - and cause unnecessary pain to the admin(s) managing that server):

[root@ichigo 5.2]# rsync -avrt rsync://mirrors.url/centos/5.2/updates/i386 --exclude=debug/ /var/www/html/CentOS/5.2/updates/
cd+++++++ i386/
cd+++++++ i386/RPMS/
>f+++++++ i386/RPMS/Cluster_Administration-as-IN-5.2-1.el5.centos.noarch.rpm
>f+++++++ i386/RPMS/Cluster_Administration-bn-IN-5.2-1.el5.centos.noarch.rpm


Please select a mirror that is relatively close to your geographical area and is complete and stable. Once you've done that, don't abuse it. The whole point of mirroring is to reduce and distribute the network load, not increase it at a single server point. Now, if you have some connectivity issues (i.e., you lose connections partially through the transfer), no worries, you can launch the command again to continue. RSYNC will pick up from the last point synchronized and continue. On a good connection, this will take less than an hour. On mine, it took close to a week.

Once you have completed the initial update, remember to schedule that rsync command in a cron job, so that your update repository is kept up to date. I have set mine to run twice a day, but for a home or small business setup, you can probably set it for longer intervals. Here's an example (using crontab -e to edit the cron schedule), apologies for the display, the rendering seems to be a tad out of wack within my browser, but the text string is OK:

30 0,12 * * * /usr/bin/rsync -avrt rsync://mirrors.rit.edu/centos/5.2/updates/i386 --exclude=debug/ /var/www/html/CentOS/5.2/updates/

Next, to create the necessary repodata header files required for the thing to work. First, install the createrepo package:

yum install createrepo

Then, create the base repodata files:

createrepo /var/www/html/CentOS/5.2/os

At this point, you should have a working mirror.

STEP 4 - CONFIGURING YOUR CLIENT SERVERS/STATIONS


What's left is to edit the yum settings on your CentOS 5.2 system(s) to use your new local mirror server. Using vi, vim,
joe (my favorite) or any other editor, open /etc/yum.repos.d/CentOS-Base.repo, comment out the existing mirrorlist and baseurl entries and insert the baseurl value with the IP of your local mirror server (replace 192.168.1.1 with whatever your server’s address is):

# CentOS base from installation media
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&re
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://192.168.1.1/CentOS/5.2/os/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1

[update]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&re
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://192.168.1.1/CentOS/5.2/updates/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
protect=1

Save the changes and your CentOS is now set to check for updates at the local mirror. Once everything runs smoothly, don't forget to backup your configurations on a regular basis.

HURDLES MET AND TROUBLES RESOLVED


Testing this thing was a real pain. I kept getting errors running yum update on the initial guinea pig client, only to realise that I just needed to provide the proper baseurl paths for the base and update sections in the .repo file. I initially thought I had a yum cache issue, so I ran:

yum clean all

Which effectively emptied the mirror cache, but didn’t fix the url issue. I eventually figured out the URL problem, and everything ran smooth after. When in doubt, Google’s your friend.