Setting up a CentOS repository
To celebrate the release (finally!) of CentOS 6, here’s how to create a local repository and keep it up-to-date.
The first step is to create the directory structure for the repository. You’ll need about 30GB of free space in the filesystem you use. Let’s assume we have a mountpoint /repo that we want to use:
mkdir -p /repo/CentOS/6/addons/i386 /repo/CentOS/6/extras/i386 /repo/CentOS/6/isos/i386 \
/repo/CentOS/6/os/i386 /repo/CentOS/6/updates/i386 \
/repo/CentOS/6/addons/x86_64 /repo/CentOS/6/extras/x86_64 \
/repo/CentOS/6/isos/x86_64 /repo/CentOS/6/os/x86_64 \
/repo/CentOS/6/updates/x86_64
If you’d like to mirror other releases (such as CentOS 5), you’ll also need to create the directory structure for those as well.
Once the directory structure is in place, we can use rsync to pull down what we don’t have. I’ve written a simple script to do this. Since this is a new repository, the first run will pull down everything, so it might be best run overnight. Also, note that I am mirroring both CentOS 5 and CentOS 6 in this script. Simply remove 5 from the verlist if you only want to mirror CentOS 6. The same applies for i386 in the archlist.
#!/bin/sh
rsync="/usr/bin/rsync -aqHz --delete"
mirror=us-msync.centos.org::CentOS
verlist="5 6"
archlist="i386 x86_64"
baselist="os updates addons extras isos"
local=/repo/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
Since your yum clients will be accessing the repository via HTTP, you’ll need to setup a webserver. Here, I’m using the standard Apache httpd that comes with CentOS. Simply modify the following lines in /etc/httpd/conf/httpd.conf:
# # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/repo" .
.
.
# # This should be changed to whatever you set DocumentRoot to. # <Directory "/repo">
After reconfiguring Apache, start it up. If everything works correctly, ensure that it will start at boot with chkconfig.
[dood@mirror ~]$ sudo /sbin/service httpd start [dood@mirror ~]$ sudo /sbin/chkconfig httpd on
The last step is configuring your clients. This can be done either through editing /etc/yum.conf, or adding to /etc/yum.repos.d:
[base] name=CentOS-$releasever - Base baseurl=http://mirror.lanigera.com/CentOS/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.lanigera.com/CentOS/RPM-GPG-KEY-CentOS-6 enabled=1 #released updates [updates] name=CentOS-$releasever - Updates baseurl=http://mirror.lanigera.com/CentOS/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.lanigera.com/CentOS/RPM-GPG-KEY-CentOS-6 enabled=1 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons baseurl=http://mirror.lanigera.com/CentOS/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.lanigera.com/CentOS/RPM-GPG-KEY-CentOS-6 enabled=1 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=http://mirror.lanigera.com/CentOS/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.lanigera.com/CentOS/RPM-GPG-KEY-CentOS-6 enabled=1 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus baseurl=http://mirror.lanigera.com/CentOS/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.lanigera.com/CentOS/RPM-GPG-KEY-CentOS-6
There you go. Cron the repo script to run daily, and you should be good.
-
Byrnejb
-
Tom K
-
Pete


