Setting Up a yum Repository
As discussed in Chapter 6, "Configuring a yum Client," yum is built on the Python programming language, which is a building block for the Red Hat/Fedora distributions. While current support is limited to the Red Hat/Fedora/Yellow Dog/Mandriva/Asp distributions, per the latest available Netcraft survey (http://news.netcraft.com/archives/2005/03/index.html), that’s over half the Linux market. If you want to learn patch management for Linux, you need to know how to use yum and configure, or "yummify," associated repositories.
The simplest way to configure a yum repository is to mirror one that already exists. Most Fedora repositories already support yum. But you do not have to mirror the entire repository, because much of it is built from installation CDs. In addition, as packages change, or if you combine packages from different mirrors, you may prefer to create yum headers on your own system rather than download them from a remote mirror.
We’ve divided this chapter into several major sections. You can take most of the packages for a repository from the installation CDs. You’ll need to manage headers for those repositories. You’ll need to configure sharing of that repository with other computers on your network. You’ll need to download other repositories associated with updates, developmental packages, and those created by third parties. Finally, you’ll need to keep these repositories up to date.
When configured, you’ll be able to update your computers from local repositories, minimizing the loads on your Internet connections, giving you more control over what is installed on your systems. You can focus on making sure that critical packages, including those related to security, are up to date. That is the essence of good patch management.
At the end of this chapter, we’ll show you how you can create a yum repository for Red Hat Enterprise Linux (RHEL) 4 clients with an authorized subscription to the Red Hat Network. If you have valid subscriptions, this is a viable alternative to the Red Hat Network Proxy Server described in Chapter 2, "Consolidating Patches on a Red Hat/Fedora Network."
7.1 Getting the Packages
You already have many of the packages that you’ll want in a yum repository: the same RPMs that are already included with the installation CDs/DVDs for your distribution. With those RPMs, you can use yum to populate the base repository and add the headers needed for easy access from the other computers on your network.
In this part of the chapter, we’ll show you how to start your repository, install yum, create an appropriate yum directory tree, add headers to the appropriate directory, and test the base repository on your local system. We’ll start with the Fedora Core 4 Updates repository. When you see how it’s done, you can use the same techniques to create other repositories on your system.
While you could use the rsync command described in earlier chapters to mirror an entire repository, each version of Fedora requires well over 10GB of space. You do not need to mirror the directory with the 6GB+ of ISO files. As described earlier in this book, there are ways to cut that down with appropriate --exclude switches to the rsync command. But if the loads on your Internet connection are not a problem, you might not need a local patch management repository in the first place.
7.1.1 Strategy
Before you create your repository, decide what you want to store locally. Viable options vary. If you have only two or three workstations, a local repository might not be so important. However, it can become profitable to configure a local repository if you have a substantial number of workstations. What you configure locally depends on your patch management strategy. Consider the following:
- To keep a substantial number of computers up to date, it can help to configure a local repository for updates. Alternatively, if your Internet bandwidth is unlimited, and the people behind your remote mirror do not object to the load, you may prefer to use remote mirrors, as they may be more up to date.
- If you frequently change the base software on your systems, you should load the installation RPMs on your repository.
- If you need packages outside the standards available on the installation CDs, look for other directories of RPMs on your favorite mirror. For example, Fedora includes the Extras repository with many useful packages.
- If you need packages simply unavailable from mirrors associated with your distribution, there are also third-party repositories described throughout this book.
- If your users test updates before they’re moved to the stable update repository, consider mirroring such repositories. You may even have reason to mirror a development repository. However, be warned that these packages are generally not stable or suitable for a production environment.
After you decide what you’re going to mirror, you can set up a yum directory tree for your local repository. In the following sections, we’ll focus on creating an Updates repository. If you have the installation CD available, you can use the same steps to create an Installation repository.
In my case, I’ve created a Fedora Core 4 repository on a system running RHEL 4, as it is a fairly stable distribution. You’ll want to leave room for future releases of Fedora Core. It might even make sense to add a new hard drive for that purpose so that the packages won’t overwhelm other files on your system. In any case, it’s an excellent idea to at least configure a separate partition for your repository.
7.1.2 Creating a yum Directory Tree
We’re assuming that you’re ready to create your own yum repository directory tree for your own network and that the tree does not have to be identical to the one on your favorite mirror. For example, assume that you’ve created the /var/ftp/pub/yum directory in a separate partition. Assume that for now, all you need to provide for are standard 32-bit systems. If you wanted to create a yum directory tree for Fedora Core 4, you might end up with the following directories:
/var/ftp/pub/yum/4/i386/os /var/ftp/pub/yum/4/i386/updates /var/ftp/pub/yum/4/i386/extras /var/ftp/pub/yum/4/i386/dag
The /var/ftp/pub directory is the default directory associated with the vsFTP server. It happens to be the default FTP server for Fedora and Red Hat distributions. With the right settings, you can link to this directory from an Apache Web server. You can also share this directory on the local network using NFS. In fact, NFS is generally preferred on a network of Linux computers because shared NFS directories can be treated as if they were on the local computer.
As the noted directories are several levels below /var/ftp/pub, you might feel like you’ll have to run the mkdir command a thousand times. There is one minor trick that can speed the process. The following command creates all needed subdirectories in one shot:
mkdir -p /var/ftp/pub/yum/4/i386/os
Note that the structure of these directories does not correspond to those you see in current Fedora Core mirrors. The directory structure of different Fedora Core mirrors varies. Unless you’re creating a mirror for public use, there is no need to create a directory structure similar to any existing Fedora Core mirror.
7.1.3 Start with a Distribution
For the purpose of this chapter, I’ve downloaded the Fedora Core 4 installation DVD, to create repositories for Fedora Core 4 systems. As noted earlier, it’ll be on a RHEL 4 computer so that I can add repositories for future releases of Fedora Core. As RHEL 4 was developed in large part from Fedora Core 3, I’ll be using Fedora-based yum packages. Naturally, the following instructions will also work for a repository configured on Fedora Core 3.
For example, if you’ve download the Fedora Core DVD, you can mount the ISO file almost as if it were a DVD/CD with the following command:
mount -o loop FC4-i386-DVD.iso /media/cdrecorder
Of course, you can "burn" the DVD .iso file (or associated CD .iso files) to appropriate media. It may be handy to have a DVD available. But, in my opinion, because you can mount the ISO directly, you don’t need a physical DVD.
A quick look at other mirrors confirms that the contents of the Fedora Core DVD are part of the os/ repository directory. You can make it part of your own local repository, by copying the contents of the DVD to the corresponding directory described earlier:
cp -ar /media/cdrecorder/* /var/ftp/pub/yum/4/i386/os/
7.1.4 Installing yum
For Fedora Core 3 and above, you’ll need at least the yum and createrepo RPMs, along with the packages associated with the way you plan to share your repository on your network (FTP, Apache, or NFS server). Earlier versions of Fedora Core did not include a createrepo RPM; if you want to create a repository from Fedora Core 1 or 2, use the yum-arch command, which is part of the yum RPM and is functionally similar to createrepo.
When the appropriate CD or DVD is mounted, you can then install the Fedora Core 3 yum and createrepo RPMs with the following commands:
rpm -Uvh /media/cdrecorder/Fedora/RPMS/yum* rpm -Uvh /media/cdrecorder/Fedora/RPMS/createrepo*
If you’re working with a RHEL 4 rebuild distribution, such as CentOS-4, the appropriate yum packages may already be installed on your system. The actual directory with these packages may vary; for example, the CentOS-4 version of the createrepo RPM is part of the CentOS-4 addons/ repository directory.
If you’re working with RHEL 4, you can install the yum and createrepo RPMs from Fedora Core 3. If you don’t have the associated installation media, you can download the RPMs directly from your favorite mirror from among those listed at http://fedora.redhat.com/download/mirrors.html.
7.1.5 Synchronizing Updates
More important than the installation RPMs are the updates. While you can use tools, such as system-config-packages, to install and remove Fedora packages from the installation files, you need access to the updates to manage patches on your system. Based on the directories described earlier, we’re planning to store RPMs from the Fedora Core 4 Updates repository on the following directory:
/var/ftp/pub/yum/4/i386/updates
Based on the rsync commands described in Chapter 2, you should find an Updates repository in the rsync mirror of your choice. Fedora rsync mirrors are listed at http://fedora.redhat.com/download/mirrors.html. One rsync mirror that I use is rsync://mirrors.kernel.org/fedora/core.
You can list the directories and files on a remote rsync server. Just make sure to include the last forward slash in your command. For example, the following command lists the directories available in the Kernel.org Fedora Core repository:
rsync rsync://mirrors.kernel.org/fedora/core/
You’ll see updates/ in the directory tree. As you continue this process, you’ll find the actual updates/ RPMs in the updates/4/i386/ subdirectory.
Search through the subdirectory. You’ll find debug/ and repodata/ subdirectories. While you may be able to use the data in the repodata/ subdirectory in your own yum repository, you don’t need to download the hundreds of megabytes of files in the debug/ subdirectory. To avoid downloading files from that directory, you’ll need to apply the --exclude switch. For example, the following rsync command synchronizes the packages from the remote updates/ repository, without debug/ packages:
As noted in Chapter 3, this synchronizes the noted remote and local directories in (-a) archive mode, with (-v) verbose output. Contents from the debug directory are (--exclude) excluded.