Monday, June 30, 2008

Configuring Yum in RHEL5

In this article I am going to discuss how we can configure Yum for DVD sources in RHEL5.
Yum is the package management tool used these days. It has replaced the old "up2date" command which use to come with RHEL4. This command used to get updates from the RHN (Redhat Network) for the installed operating system, if the user using that command had bought a support/update entitlement from Redhat. But with the new version of Redhat and then it's free clone Centos5 "up2date" has been dropped out and instead of it "yum" as been included. "yum" was there in Fedora core for a long time and was use to update packages via 3rd party repositories. It started becoming mature with Fedora and now finally when Redhat thought it to be matured enough to make it's way into RHEL it's here.

The major problem one face with Yum is to configure it for DVD/CD sources. Yum by default doesn't comes enabled for these sources and we need to explicitly enable it. I don't know what is the reason behind not enabling Yum for these sources by default but, whatever it is we can still hack "yum" on our own and can configure it to use DVD/CD install sources.

Before starting I would like to mention that I am using a DVD source in this article which is represented by "/dev/dvd" and mounted on "/media/cdrom". The steps I tell here can be easily extended for CD sources as well. Later in this article I will tell how we can configure a local yum repository and use it for package management in our LAN clients.

First of all you have to put in the media CD/DVD into your CD/DVD ROM/Writer. Then you need to mount it manually if you are login via root user in a GUI. To do so

mount /dev/dvd /media/cdrom

After mounting the DVD we need to copy the content of the DVD onto a directory. For example I have a directory /dvd/rhel5/. I will copy the whole contents of /media/cdrom into /rhel5. This is the command

cp -r /media/cdrom/* /dvd/rhel5/

After copying the contents it's time to do some modifications. First of all we need to bring the xml files defining the groups to directory one level higher.

mv /dvd/rhel5/Server/repodata/comps-rhel5-server-core.xml /dvd/rhel5/Server
mv /dvd/rhel5/VT/repodata/comps-rhel5-vt.xml /dvd/rhel5/VT
mv /dvd/rhel5/Cluster/repodata/comps-rhel5-cluster.xml /dvd/rhel5/Cluster
mv /dvd/rhel5/ClusterStorage/repodata/comps-rhel5-cluster.xml /dvd/rhel5/ClusterStorage


Now we need to delete the repodata/ directories which comes with the default install tree. The reason behind this is that in their xml files we have a string
xml:base="media://1170972069.396645#1" .....
This string is present in repmod.xml as well as primary.xml.gz. This thing creates problem with using DVD/CD sources with yum. So we need to do the following

rm -rf /dvd/rhel5/Server/repodata
rm -rf /dvd/rhel5/VT/repodata
rm -rf /dvd/rhel5/Cluster/repodata
rm -rf /dvd/rhel5/ClusterStorage/repodata

After we have deleted the default repodata/ directories it's time to re-create them using the "createrepo" command. Now this command doesn't comes by default I guess so we need to install it's rpm

rpm -ivh /dvd/rhel5/Server/createrepo-0.4.4-2.fc6.noarch.rpm

Next step is to run this command. Before running this command we need to switch to the /dvd/ directory. Then run the commands listed below

createrepo -g comps-rhel5-server-core.xml dvd/Server/
createrepo -g comps-rhel5-vt.xml dvd/VT/
createrepo -g comps-rhel5-cluster.xml dvd/Cluster/
createrepo -g comps-rhel5-cluster-st.xml dvd/ClusterStorage/

The above commands will do most part of the job. Now it's time to configure the /etc/yum.conf for our local repository. Note that we can also create separate repo files in /etc/yum.repos.d/ directory but I have tried it without any luck. So do the following

vi /etc/yum.conf

In this file type in the following: # PUT YOUR REPOS HERE OR IN separate files named file.repo

# in /etc/yum.repos.d
[Server]
name=Server
baseurl=file:///dvd/rhel5/Server/
enabled=1
[VT]
name=Virtualization
baseurl=file:///dvd/rhel5/VT/
enabled=1
[Cluster]
name=Cluster
baseurl=file:///dvd/rhel5/Cluster/
enabled=1
[ClusterStorage]
name=Cluster Storage
baseurl=file:///dvd/rhel5/ClusterStorage/
enabled=1

We can also use GPG key signing. For that write on top of the above lines

gpgenabled=1
gpgkey=file:///dvd/rhel5/RPM-GPG-KEY-fedora file:///dvd/rhel5/RPM-GPG-KEY-fedora-test file:///dvd/rhel5/RPM-GPG-KEY-redhat-auxiliary file:///dvd/rhel5/RPM-GPG-KEY-redhat-beta file:///dvd/rhel5/RPM-GPG-KEY-redhat-former file:///dvd/rhel5/RPM-GPG-KEY-redhat-release

This will be sufficient for now. Let's create the yum cache now.

yum clean all
yum update


It's all done now. We can now use "yum" command to install/remove/query packages and now yum will be using the local yum repository. Well I am mentioning some of the basic "yum" commands which will do the job for you for more options to the "yum" command see the man page of "yum".
yum install package_name Description: Installs the given package
yum list Description: List's all available package in the yum database
yum search package_name Description: Search for a particular package in the database and if found print's a brief info about it.
yum remove package_name Description: Remove's a package.

Now I will mention the steps you can use to extend this local repository to become a local http based repository so that LAN clients can use it for package management. I will be using Apache to configure this repository as it's the best available software for this job. Do configure the repository for http access via LAN clients we need to make it available to them. For that I am declaring a virtualhost entry in apache's configuration file. This is how it looks for me


ServerAdmin webmaster@server.example.com
ServerName server.example.com
DocumentRoot "/dvd/rhel5/"
ErrorLog logs/server.example.com-error_log
CustomLog logs/server.example.com-access_log common



After this service httpd start
chkconfig httpd on

Now it's time to make a yum.conf file that we will use at the client end. I am writing my yum.conf for clients. You can use it and modify according to your setup.

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
plugins=1
metadata_expire=1800
gpgcheck=1

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[Server]
name=Server
baseurl=http://192.168.1.5/Server/
enabled=1
[VT]
name=Virtualization
baseurl=http://192.168.1.5/VT/
enabled=1
[Cluster]
name=Cluster
baseurl=http://192.168.1.5/Cluster/
enabled=1
[ClusterStorage]
name=Cluster Storage
baseurl=http://192.168.1.5/ClusterStorage/
enabled=1

Copy this file to /etc/ directory of the client end and replace it with the original file there. After copying is done it's time to do this

yum clean all
yum update
rpm --import /etc/pki/rpm-gpg/*

Now you can use yum on the client end to just install any package and it will communicate with the local repo server to get the package for you. You can also use pirut in the same way to get things done.

So this is how we can configure Yum for RHEL5 Server and can also use it to create our own local repo server for the LAN. Hope you have enjoyed reading and had your hands done on this :).

16 comments:

Peter said...

The 4th 'mv' command has a slight mistake, should be:

mv /dvd/rhel5/ClusterStorage/repodata/comps-rhel5-cluster-st.xml /dvd/rhel5/ClusterStorage

Thanks for putting this guide together!

Suhas Prabhu said...

Excellent. Great article. Thank You very much.

rocky said...

thanks for that
but we found problem when i am installing rpm through yum install
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 37017186

danny said...

Amazing article, i was having a terrible time resolving the dependency issues whie trying to build.....But i too get the warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 37017186 error and as a result cannot install the pkgs...Any Help??

danny said...

yum install --nogpgcheck

Ok googled for the solution and it works fine:)

Pushpendra said...

Excellent friend...
I am very lucky to get it. Now I will be the most freqently visiting person to these links. Thanks... It worked for me...

BG said...

This is an excellent article and I really appreciate the details that are provided. I always had problems resolving dependencies and reading from DVDs without RHN registration, but this helped me a lot.

manjunath said...

it should be createrepo -g comps-rhel5-server-core.xml /dvd/rhel5Server/ ...great article thanks for posing

prashant said...

It works .thank you so much

power said...

good one thanks

Suresh said...

Thanks for this great article. But the main thing I was looking for is this. Since on our network, the servers cannot connect to Red Hat to download the updated packages, is it possible to have the yum repository update from Red Hat site and then I update my server from common repository. I am looking for an article on that..

Vivek Mano said...

Thanks a lot

Vikash Kumar Jha said...

Now we need to delete the repodata/ directories which comes with the default install tree. The reason behind this is that in their xml files we have a string
xml:base="media://1170972069.396645#1" .....
This string is present in repmod.xml as well as primary.xml.gz. This thing creates problem with using DVD/CD sources with yum.


Hi

I did not get the above statements. Canyou please explain it...how this line creates problem while using DVD/CD sources with yum.

Many Thanks

Vikash Kumar Jha said...
This comment has been removed by the author.
Himanshu Gupta said...

vi /etc/yum.repos.d/yum_server.repo
[yum]
name=YUM_SERVER
baseurl=ftp://192.168.2.100/pub/Server
enabled=1
gpgcheck=0

yum group repository creation steps.
Before these steps create .repo file.
1:- redhat cd mount on /media
2:- cd /media/Server
3:-rpm –ivh vsftpd*
4:-rpm -ivh createrepo*
5:-mkdir /var/ftp/pub/rhel58
6:-cp -av * /var/ftp/pub/rhel58
7:- cp /media/Server/repodata/comps-rhel5-server-core.xml /var/ftp/pub/rhel58/Server
9:- cd /media/Server/repodata
10:- createrepo -vg comps-rhel5-server-core.xml /var/ftp/pub/Server
11:-yum clean all
12:- yum grouplist
13:- yum groupinstall "Development Tools"

Now enjoy with local yum group repository 

Himanshu Gupta said...

vi /etc/yum.repos.d/yum_server.repo
[yum]
name=YUM_SERVER
baseurl=ftp://192.168.2.100/pub/Server
enabled=1
gpgcheck=0

yum group repository creation steps.
Before these steps create .repo file.
1:- redhat cd mount on /media
2:- cd /media/Server
3:-rpm –ivh vsftpd*
4:-rpm -ivh createrepo*
5:-mkdir /var/ftp/pub/rhel58
6:-cp -av * /var/ftp/pub/rhel58
7:- cp /media/Server/repodata/comps-rhel5-server-core.xml /var/ftp/pub/rhel58/Server
9:- cd /media/Server/repodata
10:- createrepo -vg comps-rhel5-server-core.xml /var/ftp/pub/Server
11:-yum clean all
12:- yum grouplist
13:- yum groupinstall "Development Tools"

Now enjoy with local yum group repository 