Creating a copy of an RHN repository

In this recipe, I'll show you how you can set up a yum repository for Red Hat Network-based and "plain" yum repositories.

Getting ready

Before you create a copy of an RHN repository, you need to ensure that you have a valid subscription to the repository that you want to duplicate. When this prerequisite is met, you can perform this recipe from the machine that uses the subscription.

How to do it…

Before being able to create yum repositories, we need to install a couple of tools by performing the following steps:

  1. Install the createrepo and yum-utils packages using the following command:
    ~]# yum install -y yum-utils createrepo
    
  2. Now, install the Apache web server, as follows:
    ~]# yum install -y httpd
    

Syncing RHN repositories

You can only sync RHN subscriptions that you have access to. Perform the following steps:

  1. Create a directory to hold the RHN rhel7 repository, as follows:
    ~]# mkdir /var/www/html/repo/rhel/rhel-x86_64-server-7/packages
    
  2. Now, create /mnt/iso by executing the following command:
    ~]# mkdir -p /mnt/iso
    
  3. Mount the RHEL 7 Server DVD through the following:
    ~]# mount -o loop,ro /tmp/rhel-server-7.0-x86_64-dvd.iso /mnt/iso
    
  4. Now, copy the *-comps-Server.x86_64.xml file from the RHEL Server DVD to your repo directory. The following command will help in this:
    ~]# cp /mnt/iso/repodata/*-comps-Server.x86_64.xml /var/www/html/repo/rhel/comps-Server.x86_64.xml
    
  5. Unmount the RHEL Server DVD, as follows:
    ~]# umount /mnt/iso
    
  6. Synchronize the RHEL 7 OS repository by running the following command: (This may take a while… I suggest you kill time drinking a cup of freshly ground Arabica coffee!)
    ~]# reposync --repoid=rhel-7-server-rpms --norepopath –download_path=/var/www/html/repo/rhel/rhel-x86_64-server-7/packages
    
  7. Next, create the local repository (depending on your hardware, this may take a long time), as follows:
    ~]# cd /var/www/html/repo/rhel/rhel-x86_64-server-7/
    ~]# createrepo --groupfile=/var/www/html/repo/rhel/comps-Server.x86_64.xml .
    
  8. Finally, test your repository through the following:
    ~]# curl http://localhost/repo/rhel/rhel-x86_64-server-7/repodata/repomd.xml
    

Let's create a copy of the EPEL repository through the following steps:

  1. First, install the EPEL repository, as follows:
    ~]# yum install -y epel-release
    
  2. Create a directory to hold the EPEL repository by executing the following command:
    ~]# mkdir -p /var/www/html/repo/epel/7/x86_64
    
  3. Now, download the *-comps-epel7.xml file to /repo as comps-epel7.xml, as follows:
    ~]# curl -o /var/www/html/repo/epel/comps-epel7.xml http://mirror.kinamo.be/epel/7/x86_64/repodata/xxxxxxxxxxxxxxxxxxxx-comps-epel7.xml
    

You will need to replace the multiple x's with the correct MD5 hash, as found in the repodata folder.

  1. Next, synchronize the EPEL repository by executing the following (this may take a very long time, depending on your hardware and internet speed):
    ~]# reposync --repoid=epel --norepopath –download_path=/var/www/html/repo/epel/7/x86_64
    
  2. Create the local repository (again, depending on your hardware, this may take a long time), as follows:
    ~]# cd /var/www/html/repo/epel/7/x86_64
    ~]# createrepo --groupfile=/var/www/html/repo/epel/comps-epel7.xml .
    
  3. Finally, test your repository by executing the following command:
    ~]# curl http://localhost/repo/epel/7/x86_64/repodata/repomd.xml
    

There's more…

When synchronizing RHEL 7 repositories, you will only be able to sync those you have entitlement to. To find out what entitlements you have on a given system connected to RHN, execute the following:

~]# cd /etc/yum/pluginconf.d/ && echo *.conf | sed "s/rhnplugin.conf//"|sed 's/([0-9a-zA-Z-]*).conf/--disableplugin=1/g'|xargs yum repolist && cd - >/dev/null

Whenever you synchronize a repository, try to keep the same directory structure as the original. I have found that it makes life easier when you want to rewrite your /etc/yum.repos.d files.

In an enterprise, it is useful to have a point in time when you "freeze" your yum repositories to ensure that all your systems are at the same RPM level. By default, any repository is "live" and gets updated whenever a new package is added. The advantage of this is that you always have the latest version of all packages available; the downside is that your environment is not uniform and you can end up troubleshooting for different versions of the same package.

The easiest way to achieve a "frozen" repository is to create a central location that holds all the RPMs as you would a normal yum mirror or copy.

Every x time, which you predefine, create a new directory with a timestamp, in which you hard link all the RPMs you mirror. Then finally, create a hard link to the directory, which you will later use in your repo configuration.

Here's an example:

Directories

Description

/rhel7/x86_64.all

This directory contains a mirror which is synced nightly. RPMs are added, never deleted.

/rhel7/x86_64.20150701

This directory contains hard links to the RPMs in /rhel7/x86_64, all of which were synced on 01/07/2015, along with monthly iterations of the /rhel6/x86_64.20150701 directory.

/rhel7/x86_64

This directory contains a hard link to the monthly iteration, which is deemed in production.

Of course, you need to ensure that you create a repository for each new sync!

See also

Refer to the createrepo(8) man pages for more information about creating a repository.

Also, refer to the reposync(1) man pages for more information on keeping your repository up-to-date.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset