Setting up a private RPM repo

By jbayer - Last updated: Tuesday, August 9, 2011 - Save & Share - Leave a Comment

I had a local need for a private repo, for some of our locally-built RPMS.

Since I’ve previously set up a private mirror, I decided to write a script which would both setup the directory structure I needed, and to do whatever rsyncing would be needed for a mirror. (2.8 KiB, 587 hits)

To install, just copy it into /usr/local/bin, and update the variables in the beginning to support what you want.  The variables and their explanations are:

VERSIONS=”5.5 5.6 6 6.0 6.1″  Put the versions of the OS you want to be a repo for
DIRS=”os updates”  The directories you want to mirror
OS=CentOS  OS this is a repo for
ARCH=”x86_64 i386″  Architectures
ROOT=/var/www/html  Document root for the repository, as referred to by Apache
MIRROR=rsync://  Rsync mirror
 sync=0  Set to 1 if you want to rsync


The first time you run it, it will create all the necessary directories and the initial repo files.  If you are rsyncing as well, it will take a while to sync all the files.

The script will also create a repo file which you can install into /etc/yum.repos.d.  Call it as follows:

/usr/local/bin/  releasever basearch serverip


releasever    OS release the repo file is for
basearch     Architecture the repo file is for
serverip     Either the IP address or the DNS name of the server

For example:

# /usr/local/bin/ 5.6 x86_64

would produce the following output:

name=CentOS-5.6 - Base


name=CentOS-5.6 - Updates


You could either redirect it into a file, or simply do a copy/paste.

Finally, add the following to cron to automatically run it once a day:

0 * * * *     /usr/local/bin/

Posted in Administration, Bash, Open Source • • Top Of Page

Write a comment