Thursday, June 9, 2011

How to set up a CentOS repository

If your organization is heavily reliant on a certain operating system, - say CentOS - on your workstations, it would be a good idea to set up a local repository. Each time a workstation needs a new software download or upgrade, it doesn't have to go to the internet. The idea is that our repository will work quietly every night and download the latest updates from official mirror sites. Come morning, when the machines are booted up, a fully updated local mirror will be waiting to serve the machines on the local network, saving loads of precious bandwidth and time.

The task is pretty simple. I'm sure there are probably more ways to so this, but this is how i know it. It works too!

What I will be doing is locating a mirror on the internet that supports "rsync". "rsync" is a Linux command that has a pretty straightforward function. It can synchronize a local directory or directory structure with a remote location. So what we are going to do is, find a CentOS directory structure somewhere on the internet and replicate it on our local repository machine. I use ftp.jaist.ac.jp which has a pretty fast link with our University network. You may choose one that suits your location.

Once you've found it, all you need to do is run the rsync command with a few special arguments.

rsync -avSHP --delete --exclude "local*" --exclude "isos" ftp.jaist.ac.jp::pub/Linux/CentOS/5.6 /var/www/html/CentOS/ 

The above command will create a replica of the directory structure found at ftp://ftp.jaist.ac.jp/pub/Linux/CentOS/5.6/ inside the web root of the local repository machine. The entire download is around 20GB so it will take a while on the first run. After that is done, all you've got to do is put the above command in a script and make a cron job run it every night.

Once you have the repository ready you need to tell the workstations to look for updates not on internet mirrors but in the local repository. On each of the workstations,

1. Navigate to /etc/yum.repos.d

 cd /etc/yum.repos.d

2. Backup CentOS.Base.repo file

cp CentOS.Base.repo CentOS.Base.repo.bak

3. Open the original CentOS.Base.repo with an editor like VIM

vim CentOS.Base.repo

4. For all of the sections base, updates, addons etc, comment out the line which begins with "mirrorlist". We don't want the workstation looking for mirrors. Uncomment the lines which begin with "baseurl" and change it to look like this. Replace the ip address with the ip address of your repository.

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://10.16.91.1/CentOS/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://10.16.91.1/CentOS/$releasever/updates/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
baseurl=http://10.16.91.1/CentOS/$releasever/addons/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://10.16.91.1/CentOS/$releasever/extras/$basearch/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://10.16.91.1/CentOS/$releasever/centosplus/$basearch/

gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://10.16.91.1/CentOS/$releasever/contrib/$basearch/

gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5


5. Run a yum update. The  update should now come from the local repository.

0 comments:

Post a Comment