Making a local CentOS mirror.

Following up from my last post on creating a simple yum repository, here is how to setup a local CentOS mirror.

This works much the same as with my last article, and here I’ll make it so your personal repo and your CentOS mirror repo can co-exist.

You’ll dump your CentOS mirror in /path/to/repo/CentOS, while your personal repo was put in /path/to/repo/MyRepo but the web root is at /path/to/repo/.

I want both CentOS 5.8 and 6.2

mkdir -p /path/to/repo/CentOS/{5.8,6.2}

Setup some links

cd /path/to/repo/CentOS/
ln -s 5.8 5
ln -s 6.2 6

If you didn’t setup a personal repo like I did in my last article you can do the following.

yum -y install httpd
cat <<EOF > /etc/httpd/conf.d/repo.conf
<VirtualHost *:80>
ServerName repo.example.com
ServerAlias repo
ServerAdmin ops@example.com
DocumentRoot /path/to/repo/
ErrorLog logs/repo.example.com-error_log
CustomLog logs/repo.example.com-access_log common
<Directory "/path/to/repo/*">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EOF
/etc/init.d/httpd start

Now mirror the repos with rsync.

rsync  -avrt --delete --exclude "local*" --exclude "isos" rsync://mirrors.rit.edu/centos/5.8/ /path/to/repo/CentOS/5.8/
rsync  -avrt --delete --exclude "local*" --exclude "isos" rsync://mirrors.rit.edu/centos/6.2/ /path/to/repo/CentOS/6.2/

Here I have a little script I put in cron to do a nightly sync. Obviously you don’t need to update it with cron if you want to keep everything at a certain level and control upgrade levels centerally.

cat <<EOF > /etc/cron.daily/updateCentosRepo.sh
#!/bin/bash

if [ -d /path/to/repo/CentOS/5.8 ]; then
  rsync  -avrt --delete --exclude "local*" --exclude "isos" rsync://mirrors.rit.edu/centos/5.8/ /path/to/repo/CentOS/5.8/
else
  echo "Target directory /path/to/repo/CentOS/5.8 not present."
fi

if [ -d /path/to/repo/CentOS/6.2 ]; then
  rsync  -avrt --delete --exclude "local*" --exclude "isos" rsync://mirrors.rit.edu/centos/6.2/ /path/to/repo/CentOS/6.2/
else
  echo "Target directory /path/to/repo/CentOS/6.2 not present."
fi
EOF
chmod +x /etc/cron.daily/updateCentosRepo.sh

Now create a new CentOS-Base.repo

cat <<EOF >  /etc/yum.repos.d/CentOS-Base.repo 
[base]
name=CentOS-$releasever - Base
baseurl=http://repo.example.com/CentOS/$releasever/os/$basearch/
enabled=1
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates
baseurl=http://repo.example.com/CentOS/$releasever/updates/$basearch/
enabled=1
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras
baseurl=http://repo.example.com/CentOS/$releasever/extras/$basearch/
enabled=1
gpgcheck=0

[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://repo.example.com/CentOS/$releasever/centosplus/$basearch/
enabled=1
gpgcheck=0

[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://repo.example.com/CentOS/$releasever/contrib/$basearch/
enabled=0
gpgcheck=0

[cr]
name=CentOS-$releasever - CR
baseurl=http://repo.example.com/CentOS/$releasever/cr/$basearch/
enabled=1
gpgcheck=0
EOF

Now you’re setup to kickstart and update like a boss.

Share
  • Practice GED Exams

     
    Pretty
    impressed by the variety of attentiveness on this website. You have a ton of
    amazing information here. I am sure I will check out this blog another time.

  • http://www.terminalinflection.com/ Matt

    Thanks so much for these meticulously prepared examples.  You’ve really saved me from RTFM.