How to mirror CentOS 5 and use it as a local YUM repository
I like to locally mirror CentOS 5 for a few reasons: to save on the Internet transit when my 100+ servers need the exact same updates, to not be dependent on a mirror location that is either down or temporarily unavailable, and most importantly, to have a frozen point in time of the mirror. This I specifically find necessary to maintain some consistency in Configuration Management.
I’m going to try to capture the technical details of what I had to do to get it to work for me.
Typically, I’ll PXEBOOT a server via the network and have Kickstart install and configure my servers for me. The source location that my Kickstart will use, is the local mirror of the CentOS 5 content. Also, later on, I will leverage that same content with YUM by configuring it in a local repository, to either augment my initial Kickstart installs, or to provide updates that undoubtedly come along.
I have an administration server, that I use to house my mirrors and repositories and I use rsync to mirror the data, and then use Apache to serve the content to either YUM or Kickstart using the HTTP method.
Firstly, lets mirror the important stuff. I have pretty much standardized on the 64bit version of Centos 5, so I only mirror the x86_64 related content. Here is the script I use:
/usr/local/sbin/centos_mirror
#!/bin/sh
rsync="/usr/bin/rsync -avHz --delete --stats --bwlimit=4000"
mirror=rsync://mirrors.kernel.org/centos
ver=5.5
archlist="x86_64"
baselist="os updates centosplus extras"
local=/usr/local/src/repos/centos
for arch in $archlist
do
for base in $baselist
do
remote=$mirror/$ver/$base/$arch/
echo ------------------
echo $ver/$base/$arch
echo ------------------
echo "$rsync $remote $local/$ver/$base/$arch/"
if [ ! -e $local/$ver/$base/$arch ]; then
echo "Directory does not exist, creating $local/$ver/$base/$arch"
mkdir -p "$local/$ver/$base/$arch"
fi
$rsync $remote $local/$ver/$base/$arch/
done
done
Once you have the content of the mirror, you’ll want to configure Apache such that it will serve this out via HTTP:
/etc/httpd/conf/httpd.conf
<Directory "/usr/local/src/repos">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Don't forget to restart Apache:
service httpd restart
Now that you have the CentOS 5 content mirrored, you'll want to create the corresponding YUM config file to reference it. I've hard coded my release at 5.5, but you could use $releasever in the configuration file.
/etc/yum.repos.d/CentOS-local.repo
[base]
name=CentOS - Base
baseurl=http://yourserver/centos/5.5/os/$basearch/
gpgcheck=1
gpgkey=http://yourserver/centos/5.5/os/$basearch/RPM-GPG-KEY-CentOS-5
#released updates
[update]
name=CentOS - Updates
baseurl=http://yourserver/centos/5.5/updates/$basearch/
gpgcheck=1
gpgkey=http://yourserver/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-5
#released extras
[extras]
name=CentOS - Extras
baseurl=http://yourserver/centos/5.5/extras/$basearch/
gpgcheck=1
gpgkey=http://yourserver/centos/5.5/os/$basearch/RPM-GPG-KEY-CentOS-5
#released CentOSPlus
[centosplus]
name=CentOS - CentOSPlus
baseurl=http://yourserver/centos/5.5/centosplus/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://yourserver/centos/5.5/os/$basearch/RPM-GPG-KEY-CentOS-5
That should pretty much be it.
If you are looking to set up your own PXEBOOT and Kickstart setup, you may find this other article I wrote called How to create a CentOS 5 VMware virtual machine using PXEBOOT and Kickstart helpful.
