Creating A Local Yum Repository (CentOS)

Want to support HowtoForge? Become a subscriber!
 
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)


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by sarath (not registered) on Sat, 2013-03-16 15:49.

YUM completely depends on a tool called createrepo.

This tool creates all the necessary files required for managing packages in a repository. Files like repomd.xml,filelists.xml etc.

When you fetch data from a repository, first these files are downloaded, that contains the information about the packages in the repository.

How Does YUM repository Work

Submitted by Anonymous (not registered) on Wed, 2011-03-16 07:59.

Hello,

 just wanted to say : THANKS !

Great Article !!!! Clear and Simple.

Well Done !

 

Thank You.

Avinoam

Submitted by israel (not registered) on Tue, 2009-05-12 08:37.

your tutorial is simple and all one needs to create a local repository is in this tutorial, i just dont understand why some people were not able to make this work. Well, i have, and everything is working. It couldn't get much simplier than this.... :)

Always backup files/ before making any changes !!

Submitted by Christian Kalkhoff (not registered) on Sat, 2009-04-04 20:44.

If you care, I have written down the steps necessary to set up a private mirror of CentOS 5.x on my blog: http://ninan.info/2009/04/how-to-setup-a-private-centos-mirror/

Submitted by damien (not registered) on Mon, 2008-12-01 22:12.
I really appreciate you taking the time to write this how 2 but as stated above it really sucks to try and follow it. It is missing steps and is not complete. I guess this is more of a How 2 figure out whats missing from the How 2.
Submitted by MisterEco (registered user) 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 Anonymous (not registered) on Fri, 2008-11-14 10:57.
I agree. If you're going to do a tutorial around Linux then at least be as specific and correct as possible.
Submitted by bender183 (not registered) on Mon, 2008-12-01 14:36.

2 quick suggestions for the author of this how to; next time you are thinking of writing a how to, do not do the following:

1.  hard drugs

2.  ever write a how to on a public forum again

This had to be the sloppiest how to ive ever come across in my entire life. 

Submitted by simon (not registered) on Fri, 2012-03-23 01:21.

LOL,

In my case, i'm trying to integrate a package that is not on any mirror. This does not tell how to create a repository but how to mirror one.

Submitted by Tim Harper (not registered) on Mon, 2008-12-22 17:43.
bender, I can certainly understand the frustration when given incomplete or misleading information.  Perhaps you could point out what particularly could be improved in this how to for the benefit of the other readers.
Submitted by angrywhiteman (not registered) on Thu, 2008-12-11 19:29.

To the commenter:

   1. somebody took some time to give out some knowledge. It may not be perfect, but it is more helpful then your comments.

   2. Don't be a prick.

 

 

 

Submitted by gbarta (registered user) 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 Al (not registered) on Thu, 2008-10-23 02:14.
Excellent idea, thank you!
Submitted by harm (registered user) 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 ;) 

Submitted by John Sam (not registered) on Sun, 2009-02-15 01:28.

tutorial on centos website is better I think.

http://wiki.centos.org/HowTos/CreateLocalRepos

Submitted by Malcolm (not registered) on Fri, 2009-04-24 16:38.
Hardly... no mention of using rsync there to keep the repository up to date. Use of nfs which is non-standard - what's wrong with using a web server??? Okay, the above howto has a few mistakes but there's enough to get a working Yum server going if you know a little bit about what you're doing.
Submitted by boone (registered user) on Sat, 2012-11-10 19:05.

What the CentOS document is referring to is a repository that one may host their own rpms for multiple machines in their network.

There's no need to use rsync if you're not downloading anything - the repo they discuss aren't for updates but for a site's own packages.

And in what way is NFS not standard? You mean for yum repositories? Do observe the following:

- baseurl=file:///share/CentOS/$releasever/local/$basearch

So, with NFS they are allowing users on the local net to download IF they need it (file:// ...). What if it's a machine that does not handle http ? Exactly.

yum update is all that is needed here.

Example: I have my own repo on my server here. But it's also public. So if I want to update a package on my 'client machine' there is absolutely no need for rsync. What would I be downloading? The repo? I want the package(s) updated and NOT stored (I build them and they are stored in one place; I may or may not use all of them in each machine). It's hosting only certain packages so anyone who has the repo configured on their machine simply uses yum not rsync.

The document here and the document at CentOS's wiki are accomplishing different things.

Submitted by sreedhar (not registered) on Wed, 2009-04-01 09:52.

Hi

From where the $releasever values are taken.  i have configured server and client.

but my client (rhel 5.2) takes  http://****/yum/redhat/5/ instead of 5.2.

 

pls advice.

 

sreedhar

Submitted by Anonymous (not registered) on Wed, 2012-11-07 10:29.

Hi,

I have a question:

I have one machine that has access to one sw repository from certain url and 6 that don't have access to this url, 

All these 7 machines are in the same network and I need to share the sw repository from the first machine with the others 7 machines.

how to do that?