Saturday, December 4, 2010

YUM repository creation for RHEL 5 (a step by step method)

All the below steps have to be performed as "root" user

1. Choose a directory where you would like to stage all the RPMs. This directory occupies around 3GB disk space. In this example, I am using directory /dump/rpm_repo (but you can choose directory of your choice). Create directory using the command,
 # mkdir -p /dump/rpm_repo
2. Mount Linux installation DVD to a directory (for example /media/dvd)
 # mkdir /media/dvd
 # mount /dev/dvd /media/dvd

Verification:
The command
 # ls /media/dvd
should show files in DVD

3. Copy RPM files in DVD to staging directory you have created in step 1.
 # cp -rv /media/dvd/Server/* /dump/rpm_repo

4. Now change directory to staging directory /dump/rpm_repo, to create RPM repository data.
 # cd /dump/rpm_repo

5. Install createrepo package to have createrepo command in the system that we use in next step.
 # rpm -ivh createrepo*
If you get message "package already installed", you can ignore it.

Verification:
The command
 # rpm -q createrepo
should show version of package installed instead of the message "package not installed".

6. Create RPM repository using the command (observe . at the end of the command, which means create repository with packages in current directory)
 # createrepo -g repodata/comps-rhel5-server-core.xml .
This command may take some time to finish based on your system speed.

Now repository is ready, and we have to share it. We can use NFS, FTP or HTTP for this. In this example, we share it through FTP.

7. Install FTP server package using the command
 # rpm -ivh /dump/rpm_repo/vsftpd*

Verification:
The command
 # rpm -q vsftpd
should show version of package installed instead of the message "package not installed".

8. Create a mount point of staging directory in /var/ftp, so FTP server can share this directory.
 a) Create /var/ftp/rhel_repo
     # mkdir /var/ftp/rhel_repo
 b) Edit /etc/fstab and add this entry at the end for the mount point (Caution: Doing wrong things while editing this file, may make your OS not bootable!).
     /dump/rhel_repo  /var/ftp/rhel_repo    auto   bind  0 0
 c) Now, mount /var/ftp/rhel_repo using the command
     # mount /var/ftp/rhel_repo

Verification:
The commands
 # ls /var/ftp/rhel_repo
should show files that you have in /dump/rhel_repo

Note: You can skip this complicated step (8) if you choose your directory in step (1) as /var/ftp/rhel_repo instead of /dump/rhel_repo. But you have to make sure that /var directory should have enough disk space to store 3GB of packages (which is less likely in a typical work environment).

9. Start FTP service and make it to be auto started after reboot.
 # service vsftpd start
 # chkconfig vsftpd on

Verification:
a) Find the IP address of the system using the command
 # ifconfig

b) Now verify FTP server configuration using the command
 # lftp <IP Address>:/rhel_repo -e "ls;exit"
For example,
 # lftp 192.168.1.15:/rhel_repo -e "ls;exit"

This should show all the files you have in /dump/rhel_repo

Now your YUM repository FTP server is ready to use. Configure YUM repository information like below on the system where you want to install the packages.

1. Create a new file /etc/yum.repos.d/myrhel.repo with following contents
[myrhel]
baseurl=ftp://<IP address of YUM repository server>/rhel_repo
gpgcheck=0

For example,

[myrhel]
baseurl=ftp://192.168.1.15/rhel_repo
gpgcheck=0


You can replace your choice of name instead of "myrhel" above.

2. Now you can install any package that is available in repository with command
For example you can try installing a package named "sysstat" using the command,
# yum install sysstat

No comments:

Post a Comment