Setting Up a Local Yum Mirror

A system that functions as a local yum repository mirrors repositories from the public Oracle Linux yum server.

When Oracle Linux is installed on this system, that system automatically contains the repositories that are required by the system's OS. These repositories are found in the system's /etc/yum/repos.d directory. The repositories are defined in different /etc/yum/repos.d/*.repo files.

By mirroring these default repositories, the system can function as a local yum server to service clients that have the same OS and platform as the mirror.

However, you might want the local yum mirror to also service clients that use different OS releases for other platforms. In this case, you would need to define other repositories that are required by those clients.

How to Configure the Local Yum Server

Setting up a system to function as a local yum server involves mirroring required repositories from the public Oracle Linux yum server.

The yum mirror must meet the requirements described in Prerequisites for the Local Distribution Mirror. Also, you must have completed the procedure in How to Set Up a Distribution Mirror.

You can mirror any repository available on the Oracle Linux yum server, if you have the definition for the repository configured in /etc/yum.repos.d. Mirroring repositories that the system already has available is uncomplicated. However, for other repositories, you might need to be more specific about the which repositories you want to mirror. Moreover, you might need to provide other repository configuration.

  1. Mirror all the current system's enabled repositories to the base directory.
    sudo dnf reposync --delete --download-metadata -p /var/www/html/yum 
    --delete

    Remove from the mirror any package that's removed upstream. Using this option is highly recommended.

    --download-metadata

    Include all repository metadata in the synchronization.

    If you run the command for the first time, the process might take a long while to complete. At the end of the process, the system becomes ready to provide packages to client systems with compatible OS and platforms as the mirror.
  2. Set the local mirror to host repositories for heterogeneous clients.
    1. Create the required repositories for mixed clients.

      Suppose that the server is running the latest Oracle Linux 8 release, but must provide packages for Oracle Linux 9 and Oracle Linux 7 clients. You would do the following:

      • Create /etc/yum.repos.d/9-mirror.repo with entries similar to the following example:

        [ol9_baseos_latest]
        name=Oracle Linux 9 BaseOS Latest  ($basearch)  
        baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL9/baseos/latest/$basearch/
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
        gpgcheck=1
        enabled=0
        
        [ol9_appstream]
        name=Oracle Linux 9 Application Stream Packages ($basearch) 
        baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL9/appstream/$basearch/
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
        gpgcheck=1
        enabled=0
      • Create /etc/yum.repos.d/7-mirror.repo with entries similar to the following example:

        [ol7_latest]
        name=Oracle Linux 7 Latest ($basearch)
        baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL7/latest/$basearch/
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
        gpgcheck=1
        enabled=0
        
        [ol7_optional_latest]
        name=Oracle Linux $releasever Optional Latest ($basearch)
        baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL7/optional/latest/$basearch/
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
        gpgcheck=1
        enabled=0
        
        [ol7_addons]
        name=Oracle Linux $releasever Add ons ($basearch)
        baseurl=https://yum$ociregion.$ocidomain/repo/OracleLinux/OL7/addons/$basearch/
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
        gpgcheck=1
        enabled=0

      Full yum configurations for different releases are available at https://yum.oracle.com/mirror/. Navigate to the correct distribution and architecture and download the appropriate *.repo files.

      Important:

      All entries must have enabled=0 to prevent packages from these repositories to be installed on the local yum mirror itself.

    2. Mirror each repository in the *.repo files to the base directory.
      sudo dnf reposync --repoid ol9_baseos_latest --delete --download-metadata -p /var/www/html/yum
      ...
      sudo dnf reposync --repoid ol97_latest --delete --download-metadata -p /var/www/html/yum
      ...
  3. Automate the regular client package updates from mirrored repositories through a cron script or systemd timer unit.
    For example, create a file at /etc/cron.daily/yum-mirror-update with the following content:
    #!/bin/bash
    # Regularly update yum repos
    dnf reposync --delete --download-metadata -p /var/www/html/yum
    Ensure that the file is executable.
    sudo chmod +x /etc/cron.daily/yum-mirror-update
    • If the yum mirror services mixed clients, change the script to resemble the following:

      #!/bin/bash
      
      REPOS=(repo-IDs)
      
      for REPO in ${REPOS[@]}
      do
          dnf reposync --repo=$REPO --delete --download-metadata -p /var/www/html/yum 
      done

      repo-IDs represents a comma separated list of the IDs of repositories that are required by all the clients of the mirror. These IDs are contained in corresponding /etc/yum.repos.d/*.repo files you created for those clients. In this procedure's example, the repo-IDs would represent Oracle Linux 8 repositories for clients that are compatible with the mirror. In addition, you would include ol9_baseos_latest, ol9_appstream, ol7_latest, ol7_optional_latest,ol7_addons, and so on, for the other clients.

  4. Configure clients appropriately to access these repositories.

How to Use rsync to Mirror the Oracle Linux Yum Server

Oracle provides an rsync interface to the Oracle Linux yum server repositories at the yum-rsync.oracle.com domain that maps directly to the URL structure of the Oracle Linux yum server.

You must fulfill the requirements as described in Prerequisites for the Local Distribution Mirror. Additionally, you must complete the procedure as provided in How to Set Up a Distribution Mirror.

With the rsync interface, you can easily mirror the Oracle Linux yum server for broader usage without any requirement for complex system configuration. This approach is helpful for large enterprises that want to mirror entire repository structures for all architectures. The rsync interface is an alternative method to running the reposync command to synchronize mirrored repositories.

  1. Install rsync on the system.
    sudo dnf install -y rsync
  2. Use rsync to mirror all the repositories that you intend to mirror.

    For example, to mirror all the Oracle Linux 8 repositories for all architectures, you can recursively mirror everything at the rsync://yum-rsync.oracle.com/repo/OracleLinux/OL8/ endpoint.

    rsync -arv rsync://yum-rsync.oracle.com/repo/OracleLinux/OL8 /var/www/html/yum/
    You can mirror a particular repository for a particular architecture by providing a more specific URL. For example, to mirror the current Oracle Linux 9 baseos repository for the x86_64 architecture, you would type:
    mkdir -p /var/www/html/yum/OL9/baseos/latest
    rsync -arv rsync://yum-rsync.oracle.com/repo/OracleLinux/OL9/baseos/latest/x86_64 /var/www/html/yum/OL9/baseos/latest/

How to Mirror Repositories From an ISO

The local yum mirror can be configured to mirror repositories from an ISO image to make them available to clients.

You must fulfill the requirements as described in Prerequisites for the Local Distribution Mirror. You must also complete the procedure as provided in How to Set Up a Distribution Mirror.

This task assumes that you're mirroring the repositories from an Oracle Linux 8 image. It also assumes that to provide access to the mirror, you're using a web server.

  1. Mount the ISO image at an appropriate location so you can copy its contents.
    sudo mount -o loop,ro OL8.iso /mnt
  2. Create a directory to host the repositories from the ISO.
    sudo mkdir -p /var/www/html/yum/8_ISO
  3. Copy the repositories from the ISO to the new directory.
    sudo cp -r /mnt/BaseOS /var/www/html/yum/8_ISO/
    sudo cp -r /mnt/AppStream /var/www/html/yum/8_ISO/
  4. Configure clients appropriately to access these repositories.