Mirror a Yum Repository on Oracle Linux

1
0
Send lab feedback

Mirror a Yum Repository on Oracle Linux

Introduction

The task of mirroring a yum repository holds multiple benefits. These include the following:

  • Provide access to yum repositories for systems without access to a public network
  • Improve software download times and reduce the bandwidth overhead of a large infrastructure
  • Configure local network-based installation strategies
  • Catering for a snapshot style update strategy where performing testing against a controlled software distribution environment

This tutorial shows how to mirror a yum repository for local, offline, or distributed systems access.

Objectives

In this lab, you'll learn how to:

  • Prepare a system to host the repository mirror
  • Install and configure a web server
  • Download and create a local repository
  • Configure a system to access the repository mirror

Prerequisites

  • Two Oracle Linux systems, one for the server and the other as a client
  • Storage with enough free space to contain the repository mirror

Setup the Local Yum Mirror Server

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

  1. Open a terminal and connect via ssh to the ol-server instance, if not already connected.

    ssh oracle@<ip_address_of_instance>
  2. Check the size of the repositories to mirror.

    This command will provide guidance in estimating the free disk space requirements on the repository mirror server.

    sudo dnf repoinfo

    The output shows a listing of all the enabled repositories and the current space each repository consumes. Pass the repository name as a parameter to display only a single repository.

    sudo dnf repoinfo ol8_baseos_latest

    Example Output:

    [oracle@ol-server ~]$ sudo dnf repoinfo ol8_baseos_latest
    Last metadata expiration check: 0:00:59 ago on Wed Apr 12 13:33:45 2023.
    Repo-id            : ol8_baseos_latest
    Repo-name          : Oracle Linux 8 BaseOS Latest (x86_64)
    Repo-status        : enabled
    Repo-revision      : 1681227410
    Repo-updated       : Tue Apr 11 15:36:56 2023
    Repo-pkgs          : 16862
    Repo-available-pkgs: 16856
    Repo-size          : 43 G
    Repo-baseurl       : https://yum-eu-frankfurt-1.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/
    Repo-expire        : 172800 second(s) (last: Wed Apr 12 13:33:13 2023)
    Repo-filename      : /etc/yum.repos.d/oracle-linux-ol8.repo
    Total packages: 16862

    The output shows this repository's current size with the value: Repo-size: 43G. As repositories are dynamic and grow over time, allocate enough space on the mirror server for package storage.

    The free lab environment provides the mount point /u01, which contains 50G of free space for storing these packages.

  3. Create the base directory for the local repositories.

    sudo mkdir -p /u01/yum
  4. Install the Yum-utils CLI compatibility package.

    sudo dnf install -y yum-utils

    This package provides the necessary tools to create, configure, and manage a local repository.

  5. Install the Apache HTTP server.

    sudo dnf install -y httpd
  6. Link to the base directory for the local repositories.

    sudo ln -s /u01/yum /var/www/html/yum
  7. Change the SELinux context of the base directory.

    The free lab environment requires these steps as Oracle Linux defaults SELinux to enforcing mode.

    sudo semanage fcontext -a -t httpd_sys_content_t "/u01/yum(/.*)?"
    sudo restorecon -RFv /u01/yum

    The httpd_sys_content_t allows read access but not write access to files labeled with this SELinux type by httpd.

  8. Enable the HTTP server to browse the base directory of the local repository.

    1. Edit the HTTP server configuration file.

      sudo sed -i "/^#ServerName www.example.com:80/a ServerName $(hostname -i):80" /etc/httpd/conf/httpd.conf
    2. Verify the HTTP server configuration allows the following of symbolic links.

      sudo cat /etc/httpd/conf/httpd.conf | grep "/var/www/html" -A20

      The output shows the Options Indexes FollowSymLinks for the mirror base directory location.

      Example Output:

      [oracle@ol-server ~]$ sudo cat /etc/httpd/conf/httpd.conf | grep "/var/www/html" -A20
      DocumentRoot "/var/www/html"
      
      #
      # Relax access to content within /var/www.
      #
      <Directory "/var/www">
          AllowOverride None
          # Allow open access:
          Require all granted
      </Directory>
      
      # Further relax access to the default document root:
      <Directory "/var/www/html">
          #
          # Possible values for the Options directive are "None", "All",
          # or any combination of:
          #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
          #
          # Note that "MultiViews" must be named *explicitly* --- "Options All"
          # doesn't give it to you.
          #
          # The Options directive is both complicated and important. Please see
          # http://httpd.apache.org/docs/2.4/mod/core.html#options
          # for more information.
          #
          Options Indexes FollowSymLinks
      
          #
          # AllowOverride controls what directives may be placed in .htaccess files.
          # It can be "All", "None", or any combination of the keywords:
          #   Options FileInfo AuthConfig Limit
          #
          AllowOverride None
  9. Start and enable the web server.

    sudo systemctl enable --now httpd
  10. Verify the web server service is running.

    sudo systemctl status httpd

    The output shows the status as active (running).

  11. Enable incoming HTTP connections through the firewall.

    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --reload
    

Sync Repositories to the Local Yum Mirror

Administrators can mirror any repository available on the Oracle Linux yum server, provided the definition exists in /etc/yum.repos.d on the mirror server. This ability includes repositories for mixed clients such as Oracle Linux 9 and Oracle Linux 7. For more details on configuring for hybrid clients, see the Oracle Linux documentation links at the end of this lab.

  1. Mirror the designated repository to the base directory.

    sudo dnf reposync --delete --download-metadata -p /u01/yum --repoid ol8_addons

    Note: Running this command for the first time takes a while to complete. The selection of the ol8_addons repository in this demo is solely to save time and space when running this lab.

    Leaving off the --repoid option mirrors all the mirror system's enabled repositories.

    Warning: Ensure enough free space exists on the mirror server if mirroring all the repositories.

    See the upstream documentation for the additional options available to the DNF reposync plugin.

Administrators must repeat this command when syncing the latest packages from the Oracle Linux yum server. Automating this action is possible via scripting and using cron; however, that is outside the scope of this lab.

Configure Client Access to the Local Mirror

Clients require access to the local repository mirror to receive updates and errata fixes.

  1. Open a terminal and connect via ssh to the ol-client instance, if not already connected.

    ssh oracle@<ip_address_of_instance>
  2. Import the GPG key.

    sudo wget https://yum.oracle.com/RPM-GPG-KEY-oracle-ol8 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-ol8
    sudo gpg --import --import-options show-only /etc/pki/rpm-gpg/RPM-GPG-KEY-ol8

    This GPG key is specific to Oracle Linux 8. See https://yum.oracle.com/faq.html#a10 for more information.

  3. Disable existing repositories.

    sudo dnf config-manager --disable ol8_addons

    This command disables the specific Oracle Linux yum server repository. This repository definition is in the /etc/yum.repos.d/oracle-linux-ol8.repo file, along with several other available repositories. See the Oracle Linux documentation for details if disabling all the repositories and how to ignore them in any DNF operations.

  4. Create a local repository definition file.

    Tip: To distinguish the local repositories from the public yum repositories, prefix the names of their entries with a string such as local_.

    cat << EOF | sudo tee /etc/yum.repos.d/local-yum.repo > /dev/null
    [local_ol8_addons]
    name=Oracle Linux 8 Addons ($basearch)
    baseurl=http://ol-server/yum/ol8_addons
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ol8
    gpgcheck=1
    enabled=1
    EOF

Verify the Client Configuration.

  1. Clear the yum metadata cache.

    sudo dnf clean metadata
  2. Get a list of available repositories.

    sudo dnf repolist

    Notice the local_ol8_addons in the list.

  3. List available packages in the repository.

    sudo repoquery -a --repoid local_ol8_addons

Summary

The client's output displaying a list of the packages available on the local yum mirror shows the configuration and sync works.

For More information

SSR