Linux creating local network RPM repository
After Operating system installation the next recommended step is to update the operating system to a most current patch release. This is convenient if dealing with only one operating system. In situation when 2 or more operating system must be updated at the same time and bandwidth is an issue, then looking for an alternative way to update the operating systems must have a solution. One solution is to have a local mirror of the packages of the operating system. To do this, we ned a Linux operationg system distribution based on RHEL. Please follow this guide.
Assuming these are the partitions of your hard disk:
/
/my-large-partition
/home
/var
/boot
Create directory
# mkdir -pv /my-large-partition/centos/{base,updates}
Create repository header: be sure to check createrepo package is installed
# rpm -qa | grep createrepo
# createrepo /my-large-partition/centos/base
RSYNC script
Always check http://www.centos.org/modules/tinycontent/index.php?id=30 for active mirror sites that supports rsync
#!/bin/sh
RSYNC="/usr/bin/rsync"
#RSYNC_OPTS="-aHv --delete --bwlimit=512 "
RSYNC_OPTS="-aHv --delete --exclude=debug"
if [ -f "/var/run/mirror.pid" ]; then
RUNPID=`cat /var/run/mirror.pid`
if ps -p $RUNPID; then
echo "Mirror is already running..."
exit 1
else
echo "Mirror pid found but process dead, cleaning up"
rm -f /var/run/mirror.pid
fi
else
echo "No Mirror Process Detected"
fi
echo $$ > /var/run/mirror.pid
echo -n "Mirror Started at "
date
#CentOS Mirror
# +---------------------------------------------------------------------+
# | ALL Plus Direct DVD Downloads |
# +---------------------------------------------------------------------+
$RSYNC $RSYNC_OPTS rsync://mirrors.kernel.org/centos/ /my-large-partition/centos/updates/ >> /var/log/rsync.log
# +---------------------------------------------------------------------+
# | Version 5 i386 and x86_64 Only |
# +---------------------------------------------------------------------+
#$RSYNC $RSYNC_OPTS rsync://rsync.muug.mb.ca/centos/ /my-large-partition/centos/updates/ >> /var/log/rsync.log
echo -n "Mirror Ended at "
date
rm -f /var/run/mirror.pid
CRON jobs
10 1 * * * (cd /root/scripts; ./rsync.sh) | /bin/mail my-monitoring@email.com -s "New Repository Updates 01:10 AM"
10 7 * * * (cd /root/scripts; ./rsync.sh) | /bin/mail my-monitoring@email.com -s "New Repository Updates 07:10 AM"
10 13 * * * (cd /root/scripts; ./rsync.sh) | /bin/mail my-monitoring@email.com -s "New Repository Updates 01:10 PM"
10 19 * * * (cd /root/scripts; ./rsync.sh) | /bin/mail my-monitoring@email.com -s "New Repository Updates 07:10 PM"
This will allow your YUM updates and installations to point to a local YUM repository server. Please edit CentOS-Base.repo and replace it with the values below.
[base]
name=CentOS-5 - Base
#baseurl=http://LOCAL-IP-ADDRESS/centos_5.2/
baseurl=http://LOCAL-IP-ADDRESS/updates/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
enabled = 1
#released updates
[updates]
name=CentOS-5 - Updates
baseurl=http://LOCAL-IP-ADDRESS/updates/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
enabled = 1
#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
baseurl=http://LOCAL-IP-ADDRESS/updates/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
enabled = 1
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
baseurl=http://LOCAL-IP-ADDRESS/updates/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
enabled = 1
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus
baseurl=http://LOCAL-IP-ADDRESS/updates/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
Web Server configuration:
ln -s /my-large-partition/centos/updates updates
Try browsing your server from your local network.
http://LOCAL-IP-ADDRESS/updates
That's it! Local RPM repository is now configured.

