Creating A Local Yum Repository (CentOS)

Submitted by thim (Contact Author) (Forums) on Fri, 2007-06-15 14:07. :: CentOS

Creating A Local Yum Repository (CentOS) 

Author & Content of this howto, Tim Haselaars (http://www.trinix.be)

Sometimes it can be handy to set up your own repository to prevent from downloading the remote repository over and over again. This tutorial shows how to create a CentOS mirror for your local network. If you have to install multiple systems in your local network then all needed packages can be downloaded over the fast LAN connection, thus saving your internet bandwidth.

Create the Directories:

mkdir -pv /var/www/html/centos/4/{os,updates}/i386

Replacing 4 and i386 with your major version and architecture.
Additionally you'll need some deeper directories. This is the correct location to copy the CD/DVD rpms.

Quote:
mkdir -pv /var/www/html/centos/4/os/i386/CentOS/RPMS/

The Base Repository

Copy the RPMs from the CDs/DVD to /var/www/html/centos/base.

Create the base repository headers:

createrepo /var/www/html/centos/4/os/i386/

 

The Updates Repository

Select an rsync mirror for updates: check out this list of aviable mirrors: Centos OS Mirror list and these are identified with rsync.

For example: rsync://ftp.belnet.be/packages/centos/

The mirrors share a common structure for updates. Simply append /updates/<d version>/<base arch>.

Rsync to create the updates-released repository:

/usr/bin/rsync -avrt rsync://ftp.riken.jp/centos/4/updates/i386 --exclude=debug/ /var/www/html/centos/4/updates/

This will create a complete update repository at /var/www/html/centos/4/updates/i386. The repodata directory will be created with all of the headers.

You can additionally pipe this into mail to receive an email when updates are available.

/usr/bin/rsync -avrt rsync://ftp.riken.jp/centos/4/updates/i386 --exclude=debug /var/www/html/centos/4/updates/ | /bin/mail you@example.com -s "New Repo Updates"

Next I would advise to setup a cron job to run the rsync (above). In this manner your repository is kept updated and only new updates and headers will be downloaded to your repository.

 

Yum Configuration

Edit yum.conf:

vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.*.*/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[update]
name=CentOS-$releasever - Updates
baseurl=http://192.168.*.*/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

That's it.

SPECIAL THANKS TO kylehase (for sending me corrections)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Please do not use the comment function to ask for help! If you need help, please use our forum: http://www.howtoforge.com/forums
Comments will be published after administrator approval.
Submitted by MisterEco (Contact Author) (Forums) on Tue, 2008-06-17 08:22.

Hi all!

mkdir -pv /var/www/html/centos/4/{os,updates}/i386

mkdir -pv /var/www/html/centos/4/os/i386/CentOS/RPMS/

Copy the RPMs from the CDs/DVD to /var/www/html/centos/base. - but in the previous commands we do not create base directory. What is the correct directory where the content of CD/DVD must be copied? (the correct directory structure)

Thanks a lot.

 

Submitted by gbarta (Contact Author) (Forums) on Wed, 2007-10-03 08:55.
Hi,

I would like to add two ideas to this article:
  1. We use the rsync with this switches: rsync -avH --delete --exclude-from=exclude_file. --delete deletes the package from the local repository if its not present at the source repository anymore. And the exclude list is a long list about graphical or other not needed programs for a server. They are useful to keep the repo size low.
  2. We run the createrepo command only when a new package has been added to the repo. For example: FIND_OS=`find repo/path -ctime -1 | wc -l`
    if [ $FIND_OS -gt 0 ]
    then
         /usr/bin/createrepo -u repo/url -o repo/path repo/path >> /dev/null
    fi

Submitted by harm (Contact Author) (Forums) on Fri, 2007-06-15 15:57.

Wouldn't it be far better to install a cache consisting of only usefull packages then just downloading the complete list of packages?

eg. why download kde/gnome etc. to your mirror when your not even using them ;)