How to configure offline yum repository using DVD and HTTP or Apache server over the network in RHEL / CentOS 7

How to configure offline yum repository using DVD and HTTP or Apache server over the network in RHEL / CentOS 7

In this article I will show you the steps to configure an offline yum repository in your network using http server

IMPORTANT NOTE: I had already written an aticle to use yum with apache but that was tested and validated with RHEL 5 and 6, and with RHEL 7 some httpd configuration option have changed. If you are using older version of RHEL please follow below link

To make this work we would need a basic http server so install all the http related packages.
Now before creating a http based yum repository, create an offline repo using the RHEL/CentOS dvd.

Next install httpd rpm and its dependency using yum

# yum install httpd -y

Next it is time to configure our http server
Edit your main configuration file i.e. "/etc/httpd/conf/httpd.conf" and add below content at the end of the file

NOTE: Here I will use /var/www/html as my source path where the RHEL/CentOS dvd will be mounted. You can change the path accordingly as per your requirement

Alias /web "/var/www/html/"
<VirtualHost 192.168.1.6:80>
        ServerAdmin root@server.golinuxhub.com
        ServerName golinuxhub-server
        DocumentRoot /var/www/html
        ErrorLog logs/error_log
  <Directory "/var/www/html/">
     Options Indexes MultiViews
     AllowOverride All
     Require all granted
  </Directory>
</VirtualHost>

If you have firewalld running on your system then you can run below command to add firewalld rules for httpd

# firewall-cmd --permanent --add-service=http
success

# firewall-cmd --reload
success

Next restart your httpd service

# systemctl restart httpd

Make sure the RHEL/CentOS dvd is mounted on your source directory i.e. /var/www/html

# mount /tmp/rhel-server-7.4-x86_64-dvd.iso /var/www/html/
mount: /dev/loop0 is write-protected, mounting read-only

# ls /var/www/html/
addons  EFI  EULA  extra_files.json  GPL  images  isolinux  LiveOS  media.repo  Packages  repodata  RPM-GPG-KEY-redhat-beta  RPM-GPG-KEY-redhat-release  TRANS.TBL

Next try to access your http server using http://192.168.1.6/web/ on your browser
NOTE: Replace the host IP (192.168.1.6) with your node IP

How to configure offline yum repository using DVD and HTTP or Apache server over the network in RHEL / CentOS 7

If all is good proceed to next step or else if you face any issue follow "/etc/httpd/logs/error_log" for more information on the issue

It is time to re-configure our repo file which for me is "/etc/yum.repos.d/rhel.repo" with below content

[RHEL_Repo]
name=Red Hat Enterprise Linux 7.4
baseurl=http://192.168.1.6/web/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

NOTE: The gpg keys are by default installed on systems by a Red Hat release package for your type of installation hence you can use the above path and make sure that it exists

Here as you see my baseurl reflects my http server which contains the rpm from the rhel dvd.

Next save and exit the file

Next let's clean the cache

# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: RHEL_Repo
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

# rm -rf /var/cache/yum

Now let's see if our new repo is working as expected

# yum repolist all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
RHEL_Repo                                                                                           | 4.1 kB  00:00:00
(1/2): RHEL_Repo/group_gz                                                                           | 137 kB  00:00:00
(2/2): RHEL_Repo/primary_db                                                                         | 4.0 MB  00:00:00
repo id                                      repo name                                                       status
RHEL_Repo                                    Red Hat Enterprise Linux 7.4                                    enabled: 4,986
repolist: 4,986

So as you see my repo "RHEL_Repo" is enabled and has 4,986 rpms.
Now you can use the same repo file in your network and use this offline repository.

How to use http or apache service running on a different port other than 80 with my yum repository?

By default we use port 80 for configuring http server but for some reason if you wish to use a different port number then also nothing should change and you can follow the same procedure.

You may need to do some conf changes for your httpd config file as below

Change

Listen 80
to
Listen 8080

and virtual hosting configuration as below

Alias /web "/var/www/html/"
<VirtualHost 192.168.1.6:8080>
        ServerAdmin root@server.golinuxhub.com
        ServerName golinuxhub-server
        DocumentRoot /var/www/html
        ErrorLog logs/error_log
<Directory "/var/www/html/">
   Options Indexes MultiViews
   AllowOverride All
   Require all granted
</Directory>
</VirtualHost>

Add necessary firewalld rules for new port

# firewall-cmd --permanent --add-port=8080/tcp
success

# firewall-cmd --reload
success

Restart your httpd service

# systemctl restart httpd

Validate your httpd server on the browser

How to configure offline yum repository using DVD and HTTP or Apache server over the network in RHEL / CentOS 7

Next also change the yum repo file as below

[RHEL_Repo]
name=Red Hat Enterprise Linux 7.4
baseurl=http://192.168.1.6:8080/web/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

I hope the article was useful.

Leave a Comment