Create a Local CentOS Repository using ISO File (Offline Mode)
This tutorial is going to show you how to create a local CentOS Repository on your CentOS machine using the CentOS ISO DVD...
There are a few things to note in this tutorial however:
- This tutorial will help you set up a local Repo successfully, however the availability of RPMs strictly depends on the version of the CentOS DVD you are using. Since this Repo is created using the DVD as a RPM source, you wont get all the RPMs the you may want.. but definately, the necessary ones are always covered in the DVD..
- This tutorial can be followed to create a local Repo where there is no internet connectivity present (Hence, i call it as an Offline Repo !!)
- There are other ways of setting this up as well, but i have documented it using standard steps that are generally very easy to manipulate on any CentOS machine irrespective of version.
NOTE: I am using CentOS 5.8 64 Bit to create this Repo. You can use any version for your repo.
I have already downloaded the DVD from CentOS mirror. I suggest you have the ISO file ready with you before you start this tutorial
I am using a standard CentOS machine here.. done absolutely nothing special with it.. just installed it as a VM on VMware Workstation.. that's it !!
I have logged in as root and ran an ifconfig to note the IP Address of the VM. We will use the IP address to configure the YUM Server with Apache in later steps
Next, run fdisk -l to check free space in your machine. Depending on your CentOS DVD version, you will need approximately 10 - 20 GB of HDD space on root partition ("/") as shown.
# fdisk -l
Next, mount the CentOS ISO file (DVD) on your machine. To check whether it has been successfully mounted, run the mount command as shown. You should see the output as shown below:
Once mounted, we now need to create a new directory in /var/www/html folder.
# cd /var/www/html
# mkdir centos58
Next, we now need to copy all the RPMs from the mounted ISO File (DVD) to this new folder (centos58)
Browse to the CentOS DVD. The RPMs are generally located in CentOS folder as shown below
# cd /media/CentOS_5.8_Final/CentOS
if we do a word count (wc -l), we can see 3536 files present at this location (This number can vary depending on your CentOS DVD release)
NOTE: Out of 3536 files, one of them is not an RPM.. so take care when you copy the files from here
Copy ONLY the RPM files from the DVD to the newly created folder (centos58)
# cp *.rpm /var/www/html/centos58/
Copying of files takes time (approx 3-4 mins) as roughly 4 GB of RPMs are being copied from the mounted ISO to the new location that we just created
Once the copying is done, if you do a word count (wc -l) in the centos58 folder, you should see one less file than what we earlier had recorded. This is exactly what we wanted.
Now once all the RPMs have been successfully copied, we need to execute one RPM from it named createrepo.
createrepo is a program that creates a repomd (xml-based rpm metadata) repository from a set of RPMs. To know more about createrepo, click HERE.
# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
You then run the command:
# createrepo .
You can run this command from withing that directory or even one level up as createrepo will
descend down to all LOWER directories too. We ran this command at /var/www/html/centos58
directory level When you run createrepo, it will generate a directory called repodata in the directory where
it is run.
NOTE: This step also takes little time (approx 3-4 mins) depending on the number of RPMs present
With this step, our Repo is almost complete. We will now setup apache server (provided with CentOS installation)
# vi /etc/httpd/conf/httpd.conf
In this file, you only have to make changes in two places.
ServerAdmin root@<YOUR CENTOS MACHINE'S IP ADDRESS>
SERVERNAME <YOUR CENTOS MACHINE'S IP ADDRESS>:80
Once the changes are done, save and close the file.
Next, enable the httpd service to be switched on even after boot using chkconfig command
Start the httpd service if its stopped
# chkconfig --levels 235 httpd on
# service httpd status
# service httpd start
NOTE: If there is some error message while starting the httpd service, suggest you check out the httpd.conf file that we earlier edited for any errors.
Next, we now need to create our own repo file. For that, go to /etc/yum.repo.d folder and rename all the existing repo files (*.repo) to .repo.old (OR) you can just create a new folder there and move all these repo files in it (as down below)
# cd /etc/yum.repo.d
# mkdir old
# mv CentOS-* old/
With this done, create a new .repo file as shown below:
# vi localCentOSrepo.repo
In this new file, type in the following info:
Once entered, save and close the file.
Clean the Repository
# yum clean all
List the Repository
# yum repolist
If you get an output similar to the one below, then you have successfully configured a local CentOS yum repository on this machine :-)
To test it out, try installing something.. in my case i wanted to install Xen Hypervisor packages, but i didn't know what all dependencies were required with it. But, since i now have a local repository, i dont have to worry about all that anymore.. the local repo sets up the install process, checks for dependencies and installs them as well, all in one go :-)
As you can see, it resolves dependencies as well
In case you get a warning as shown below, then dont worry. Its cause your Repository's Keys are not signed. Simply run the following command and try to install again.. it should work out just fine..
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-*
NOTE: You only have to run this command once. Not required each time at all..
So we now try installing Xen again... and this time Xen installs successfully :-)
Just to confirm :-)