Skip to main content

LFCS Certification Course

Chapter #28: Setting Up a Network Repository on RHEL

In this chapter, you will learn how to set up a local network repository on RHEL 9 and configure server and client machines to install packages from the local repository.

Installing, updating, and removing (when needed) installed programs are key responsibilities in a system administrator’s daily life.

When a machine is connected to the Internet, these tasks can be easily performed using a package management system such as dnf, yum, or zypper, depending on your chosen distribution.

You can also download standalone .rpm files and install them with dnf or rpm, respectively.

However, when a machine does not have access to the World Wide Web, other methods are necessary. Why would anyone want to do that?

The reasons range from saving Internet bandwidth (thus avoiding several concurrent connections to the outside) to securing packages compiled from source locally and including the possibility of providing packages that, for legal reasons (for example, software that is restricted in some countries), cannot be included in official repositories.

That is precisely where network repositories come into play, which is the central topic of this chapter.

Creating a Network Repository Server on RHEL

As a first step, we will handle the installation and configuration of a RHEL 9 box as a repository server [IP address 192.168.0.17] and a RHEL 9 machine as a client.

As for Ubuntu, we will cover it in a separate chapter 29, which explains how to set up your own private repository.

Our first choice will be the way in which clients will access the repository server using FTP and HTTP, which are the most commonly used, and which will also allow us to display the package listing using a web browser.

Next, we need to create directories to store the .rpm packages. We will create subdirectories within /var/www/html/repos accordingly.

For our convenience, we may also want to create other subdirectories to host packages for different versions of each distribution (of course, we can still add as many directories as needed later) and even different architectures.

An important thing to take into consideration when setting up your own repository is that you will need a considerable amount of available disk space (~20 GB or more).

If you don’t, resize the filesystem where you’re planning on storing the repository’s contents, or even better, add an extra dedicated storage device to host the repository.

That being said, we will begin by creating the directories that we will need to host the repository:

mkdir -p /var/www/html/repos/rhel/9/BaseOS

After we have created the directory structure for our repository server, we will initialize in /var/www/html/repos/rhel/9/BaseOS the database that keeps track of packages and their corresponding dependencies using createrepo.

Install createrepo if you haven’t already done so:

dnf install createrepo

Then initialize the database:

createrepo /var/www/html/repos/rhel/9/BaseOS

Updating the Repository on RHEL

Assuming that the repository server has access to the Internet, we will pull an online repository to get the latest updates of packages.

If that is not the case, you can still copy the entire contents of the Packages directory from a RHEL 9 installation DVD. In this tutorial, we will assume the first case.

In order to optimize our download speed, we will choose a RHEL 9 mirror from a location near us. Go to https://access.redhat.com/downloads and pick the one that is closer to your location.

Then, navigate to the BaseOS directory inside the highlighted link and then choose the appropriate architecture.

Once there, copy the link in the address bar and download the contents to the dedicated directory in the repository server: