How To Set Up Your Own RPM Repository (repo)
Even if you have more than one system, the benefits of having your own local mirror of RPMs are substantial: faster updates, better synchronization of system packages, etc. It’s also pretty easy to do.
- Install createrepo via yum: yum -y install createrepo
- You might as well install “repoview”, too:
- yum -y install repoview
- Install rsync via yum if you don’t have it installed already: yum -y install rsync
- Pick a file system and directory to contain your copy of the repository. Remember, this repository will only grow over time, so take that in to consideration. You don’t want to pick a volume that will cripple your entire system if it fills up. In this example, let’s use /export/repos, and create the following directories:
- /export/repos/6/x86_64
- /export/repos/6/i386
- Edit /etc/exports to contain:
- /export/repos *(ro,sync)
- Start the NFS server process:
- /etc/init.d/nfs start
- chkconfig –level 345 nfs on
- Mount the file system on all of your hosts. I personally use automounter, but it is not required:
- mount myserver:/export/repos /home/repos
- Put together a small script (I have a sample one attached to this post) which will rsync the repository from a known good mirror source to the directory you created in step 3. (rsync_repos.pl)
- #!/bin/sh
# rsync (mirror) the latest updates locally.
# Rich West
#CREATEREPO=0RSYNC_OPTIONS=” \
–verbose –progress –stats \
–delete \
–archive \
–exclude debug \
–exclude repodata”if [ “$1” != “-d” ] || [ “X$2” = “X” ]; then
echo “Usage: $0 -d <32bit | 64bit | all> [-r]”
echo
exit;
fi
MIRROR1=/export/repos/6/i386/updates
MIRROR2=/export/repos/6/x86_64/updates
RSYNC_HOST=distro.ibiblio.org::distros/fedora/linux/core/updates/6
rm -rf $MIRROR1/.olddata $MIRROR2/.olddata
OUTFILE=/tmp/rsync.outputif [ “$2” = “32bit” ] || [ “$2” = “all” ]; then
##
# Sync up the ‘updates’ tree for the 32bit distribution.
##
/bin/nice /usr/bin/rsync $RSYNC_OPTIONS \
$RSYNC_HOST/i386/ $MIRROR1 \
>> $OUTFILE
##
# Build the repo data
##
if [ “$CREATEREPO” = “1” ]; then
/usr/bin/createrepo -q $MIRROR1
cd $MIRROR1
/usr/bin/repoview -q .
cd /
fi
fiif [ “$2” = “64bit” ] || [ “$2” = “all” ]; then
##
# Sync up the ‘updates’ tree for the 64 bit distribution
##
/bin/nice /usr/bin/rsync $RSYNC_OPTIONS \
$RSYNC_HOST/x86_64/ $MIRROR2 \
>> $OUTFILE
##
# Build the repo data
##
if [ “$CREATEREPO” = “1” ]; then
/usr/bin/createrepo -q $MIRROR2
cd $MIRROR2
/usr/bin/repoview -q .
cd /
fi
fi
- #!/bin/sh
- Update your yum repo files to point to your local copy of the repository and disable the external ones:
-
- Create /etc/yum.repos.d/my.repo:
- [My-updates]
name=My Repo Mirror – $releasever – $basearch
baseurl=file:///home/repos/$releasever/$basearch/updates/
enabled=1
gpgcheck=0
- [My-updates]
- Disable the Fedora “updates” repo /etc/yum.repos.d/fedora-updates.repo:
- Change all of the entries to contain “enabled=0”
- Create /etc/yum.repos.d/my.repo:
-
- Create a cronjob to sync your repo and the known-good repo mirror nightly:
- crontab -e
- 00 04 * * * /home/root/bin/rsync_repos.pl -d all -r
In my case, I figured the one to keep sync’ed was the one that changed the most: the updates repository. However, your mileage may vary, and you can apply the above to sync’ing just about any repository. I also chose one that used ‘rsync’ versus having to script a bit “wget” or another web mirroring tool.