In this recipe, I'll show you how you can set up a yum repository for Red Hat Network-based and "plain" yum repositories.
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.
Before being able to create yum repositories, we need to install a couple of tools by performing the following steps:
createrepo
and yum-utils
packages using the following command:~]# yum install -y yum-utils createrepo
~]# yum install -y httpd
You can only sync RHN subscriptions that you have access to. Perform the following steps:
rhel7
repository, as follows:~]# mkdir /var/www/html/repo/rhel/rhel-x86_64-server-7/packages
/mnt/iso
by executing the following command:~]# mkdir -p /mnt/iso
~]# mount -o loop,ro /tmp/rhel-server-7.0-x86_64-dvd.iso /mnt/iso
*-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
~]# umount /mnt/iso
~]# reposync --repoid=rhel-7-server-rpms --norepopath –download_path=/var/www/html/repo/rhel/rhel-x86_64-server-7/packages
~]# cd /var/www/html/repo/rhel/rhel-x86_64-server-7/ ~]# createrepo --groupfile=/var/www/html/repo/rhel/comps-Server.x86_64.xml .
~]# 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:
~]# yum install -y epel-release
~]# mkdir -p /var/www/html/repo/epel/7/x86_64
*-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.
~]# reposync --repoid=epel --norepopath –download_path=/var/www/html/repo/epel/7/x86_64
~]# cd /var/www/html/repo/epel/7/x86_64 ~]# createrepo --groupfile=/var/www/html/repo/epel/comps-epel7.xml .
~]# curl http://localhost/repo/epel/7/x86_64/repodata/repomd.xml
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 |
---|---|
|
This directory contains a mirror which is synced nightly. RPMs are added, never deleted. |
|
This directory contains hard links to the RPMs in |
|
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!