How to Setup a Local YUM Repository Server in Rocky Linux 8/9

Introduction

As a Linux Administrator, one of the common tasks is setting up a local YUM repository server. This is especially useful in environments where internet access is limited, or when you want to save bandwidth by hosting packages locally. In this guide, we will learn how to configure a YUM server in Rocky Linux 8/9.

Why Setup a Local YUM Repository?

  • To save internet bandwidth in large environments.
  • To ensure faster installation of packages from a local source.
  • To maintain control over which package versions are available.
  • To support offline installations and updates.

Step 1: Install Required Packages

First, install the required packages on your server:

sudo dnf install -y createrepo httpd wget

Step 2: Mount the Rocky Linux ISO

Download the Rocky Linux 8/9 ISO image and mount it:

mkdir -p /mnt/iso
mount -o loop Rocky-8.9-x86_64-dvd1.iso /mnt/iso

Step 3: Copy Packages to Repository Directory

Create a local directory for your repository and copy packages:

mkdir -p /var/www/html/localrepo
cp -r /mnt/iso/AppStream /var/www/html/localrepo/
cp -r /mnt/iso/BaseOS /var/www/html/localrepo/

Step 4: Create Repository Metadata

Now create metadata using createrepo:

createrepo /var/www/html/localrepo/BaseOS
createrepo /var/www/html/localrepo/AppStream

Step 5: Configure HTTP Server

Enable and start Apache:

systemctl enable httpd --now

Step 6: Configure Local YUM Repo File

Create a new repo configuration file:

vi /etc/yum.repos.d/local.repo

Add the following lines:

[local-baseos]
name=Local BaseOS
baseurl=http://<your-server-ip>/localrepo/BaseOS
enabled=1
gpgcheck=0

[local-appstream]
name=Local AppStream
baseurl=http://<your-server-ip>/localrepo/AppStream
enabled=1
gpgcheck=0

Step 7: Clear Cache and Verify

Run the following commands:

dnf clean all
dnf repolist

Additional Tips for Linux Administrators

  • Always keep a backup of your ISO or RPM repository in case of corruption.
  • You can restrict repo access using firewall or Apache authentication.
  • Consider using reposync if you want to mirror repositories from the internet.

Conclusion

Setting up a local YUM server in Rocky Linux 8/9 is a critical skill for system administrators managing large infrastructures. This not only optimizes bandwidth but also provides more control and reliability over package installations.

Leave a Reply

Your email address will not be published. Required fields are marked *