Sunday, 13 January 2013

Creating a Local Yum Repository for RedHat/Cent OS Linux


Reducing the costs of I.T without reducing the functionally of your systems is one of the major obstacles to overcome. One of these costs is bandwidth, especially in India.

One of the first bandwidth saving tips any organization should know is the importance of creating a local YUM repository on your LAN. Not only you decrease the time it takes to download and install updates, you also decrease bandwidth usage. This saving will definitely please the suites of any organization.

This “How To” show’s you a simple yet effective way of setting up your local YUM server and client.

I am using two CentOS 5.2 servers in this tutorial:

1.server1.example.com (Yum Repo Server)
2.server2.example.com (Yum Client)

Prerequisites:

  • Above servers are installed with CentOS 5.2.
  • A Web server is installed and configured on the Yum Repo Server.
  • Sufficient storage space (at least 5GB for each 5.x) on the Yum Repo Server.
  • Yum Repo Server should have internet connectivity.
  • Both machines can connect to each other via LAN (do a ping test).

Configure Yum Repo Server as follows:

Step 1. Create the following directories as root on Yum Repo Server.
# mkdir -p /var/www/html/centos/5.5/os/i386
# mkdir -p /var/www/html/centos/5.5/updates/i386
# mkdir -p /var/www/html/centos/5.5/os/x86_64
# mkdir -p /var/www/html/centos/5.5/updates/x86_64
# mkdir -p /var/www/html/centos/5.4/os/i386
# mkdir -p /var/www/html/centos/5.4/updates/i386
# mkdir -p /var/www/html/centos/5.4/os/x86_64
# mkdir -p /var/www/html/centos/5.4/updates/x86_64
# mkdir -p /var/www/html/centos/5.3/os/i386
# mkdir -p /var/www/html/centos/5.3/updates/i386
# mkdir -p /var/www/html/centos/5.3/os/x86_64
# mkdir -p /var/www/html/centos/5.3/updates/x86_64
# mkdir -p /var/www/html/centos/5.2/os/i386
# mkdir -p /var/www/html/centos/5.2/updates/i386
# mkdir -p /var/www/html/centos/5.2/os/x86_64
# mkdir -p /var/www/html/centos/5.2/updates/x86_64
# mkdir -p /var/www/html/centos/5.1/os/i386
# mkdir -p /var/www/html/centos/5.1/updates/i386
# mkdir -p /var/www/html/centos/5.1/os/x86_64
# mkdir -p /var/www/html/centos/5.1/updates/x86_64
# mkdir -p /var/www/html/centos/5.0/os/i386
# mkdir -p /var/www/html/centos/5.0/updates/i386
# mkdir -p /var/www/html/centos/5.0/os/x86_64
# mkdir -p /var/www/html/centos/5.0/updates/x86_64
# mkdir -p /var/www/html/centos/5/os/i386
# mkdir -p /var/www/html/centos/5/updates/i386
# mkdir -p /var/www/html/centos/5/os/x86_64
# mkdir -p /var/www/html/centos/5/updates/x86_64

Step 2. Create a bash script that will rsync your local Yum Repo Server with internet Yum Mirror.
Note: Select any fast mirror site which is near to your location and is capable of rsync
I am using “Linux Kernel Archives” (rsync://mirrors.kernel.org/centos) for this tutorial.

# vi yum-repo-update.sh

Open a file using the above command ,copy paste the below entries in that and save the file.

#!/bin/sh
rsync="rsync -avrt --bwlimit=256 --exclude=debug/"
mirror=rsync://mirrors.kernel.org/centos
verlist="5 5.0 5.1 5.2 5.3 5.4 5.5"
archlist="i386 x86_64"
baselist="os updates"
local=/var/www/html/centos/
for ver in $verlist
do
for arch in $archlist
do
for base in $baselist
do
remote=$mirror/$ver/$base/$arch/
$rsync $remote $local/$ver/$base/$arch/
done
done
done
Step 3. Give execute permission for the script.

# chmod 755 yum-repo-update.sh

Step 4. Add the bash script to your crontab to update your local repository every night (01H00 in this case)

# crontab -e

# Update Local YUM repo update from mirrors.kernel.org/centos
0 1 * * * /path/to/yum-repo-update.sh


Configure YUM client as follows:

Step 1. Rename all existing yum repositories from *.repo to *.old

# cd /etc/yum.repos.d/
# mv *.repo *.old

Step 2. Create a new local repo file ,copy paste the below content and save the file.

# vi /etc/yum.repos.d/localCentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://server1.example.com/centos/$releasever/os/$basearch
gpgcheck=1
gpgkey=http://server1.example.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://server1.example.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://server1.example.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-5

Step 3. Test your setup by running a yum update on your client machine.

# yum clean all
# yum repolist
# yum update

No comments:

Post a Comment