Create an Apache-based YUM/DNF Repository in CentOS and RedHat Linux 8

Yellowdog Updater Modified (YUM) or Dandified YUM (DNF) are the software package managers to manage RPM-based Linux distributions. Using YUM or DNF tool, we can install , update, remove, search rpm packages without having to manually update or install each rpm packages. Following are the advantages to create local repositories.

  1.  RPM packages are available locally, you don’t require internet connection to install or update the packages.
  2.  Install and update of packages are performed quickly as the packages are being downloaded locally or via local network.
  3.  Local repository can be accessed via Web Server, FTP or Local LAN.
  4.  To resolve dependencies of RPM packages.

In this post, we will guide you to set up an Apache-based YUM/DNF repository on Red Hat/ CentOS Linux 8 using installation DVD/ISO.
RHEL/CentOS 8 Linux ships with two repositories:
BaseOS:- BaseOS repository contains main OS packages 
Application Stream: – Application Stream repository we have all application related packages, developer tools and databases etc.
You may also like to read:
. Red Hat Enterprise Linux 8.1 Installation with Screenshots
CentOS Linux 8 Installation with Screenshots
How to enable or disable Red Hat Subscription-Manager in RHEL Linux

Prerequisites

You will need two RedHat/CentOS Linux 8 running Instance. One for Local Repository Server and the other one is for Local Client machine. Note: In your case IP Address might be different.
Server = 192.168.56.124
Client = 192.168.56.114
DVD/ISO
root or sudo privileges access
Following are the steps to create Local Repository
Step 1: Mount RHEL/CentOS DVD/ISO/USB Stick, should contains RHEL/CentOS OS Image. Copy media content or ISO file to the below created directory and go to the directory and extract ISO file. Take a backup or move of the existing repo files from “/etc/yum.repos.d” which are not in use if any.
Mount ISO Image:
$ sudo mount -o loop CentOS-8.1.1911-x86_64-dvd1.iso /mnt
Create a directory (In your case directory name may be different).
# mkdir /local_repo
# cd /local_repo
Extract the ISO file with 7zip command below (Click on picture below to enlarge it).
# 7z x CentOS-8.1.1911-x86_64-dvd1.iso

Step 2: Create a local repository file “local.repo” under “/etc/yum.repos.d/” directory and add the following details (Click on picture below to enlarge it).
# touch /etc/yum.repos.d/local.repo
# chmod u+rw,g+r,o+r /etc/yum.repos.d/local.repo

# vi /etc/yum.repos.d/local.repo
Step 3: Paste below configuration, save & exit.
[Local_Repo_BaseOS]
name=Local_Repo_BaseOS
metadata_expire=-1
enabled=1
gpgcheck=1
baseurl=file:///local_repo/BaseOS/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[Local_Repo_AppStream]
name=Local_Repo_AppStream
metadata_expire=-1
enabled=1
gpgcheck=1
baseurl=file:///local_repo/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Step 4: Finally, run the createrepo command (Click on picture below to enlarge it).

# createrepo /local_repo/

Verify that the local repository was created (Click on picture below to enlarge it):

Step 5: Test and verify your local repository, clean and check and verify repolist (Click on picture below to enlarge it).
# dnf clean all
# dnf repolist

Step 6: Install package using Local YUM/DNF Repository
Let’s install Apache Web Server using local repository (Click on picture below to enlarge it).

Step 7: Setup Apache Web Server

As we have already installed Apache Web Server in previous step. Start, Enable & check the Status of “httpd.service” (Click on picture below to enlarge it).
# systemctl start httpd.service
# systemctl status httpd.service
# systemctl enable httpd.service

Step 8: Firewall Configuration
Allow http | https service on System Firewall with following commands (Click on picture below to enlarge it).
# firewall-cmd –zone=public –permanent –add-service=http
# firewall-cmd –zone=public –permanent –add-service=https
# firewall-cmd –reload

Step 9: Configure Apache
As you can see in the above “httpd.service” is up and running. You can verify on your web browser (http://localhost/IP Address). The default Apache Web page should displayed. Open Apache configuration file, find the line “DocumentRoot” and “/var/www” change as below (Click on picture below to enlarge it).

DocumentRoot “/local_repo”

<Directory “/local_repo”>
    Options All Indexes FollowSymLinks
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
#  vim /etc/httpd/conf/httpd.conf

Restart httpd.service after above changes in Apache Config files also check the Apache parameter (Click on picture below to enlarge it).

Note: Remove “/etc/httpd/conf.d/welcome.conf” file, if the “httpd.service” is running and Syntax is “OK”.
Step 10: Setting up the client
On the client system, add or create local repo from the server to the client machine.
# vi /etc/yum.repos.d/local-rhel8.repo
Add the following lines:
Note: On baseurl, “192.168.56.124” is our DNF/YUM server IP Address
[LocalServer]
name=LocalServerRepo
enabled=1
gpgcheck=0
baseurl=http://192.168.56.124
save and exit file.

# yum clean all
Step 11: Test the repo installing a package and also browsing the repository
Installing a Package called “mc” with command below.
# yum install mc

Browsing Repository:


This indicates that our Apache-based local YUM/DNF repository is working as expected in CentOS and Red Hat Enterprise Linux 8, using the installation DVD or ISO file. Please share it with others and use comment box below to raise a query if any. Also follow us on tecluesdotcom Facebook Official Page.

Leave a Comment