Share on Social Media

Discover how to setup local Yum repository in RHEL 7 using an ISO file with our detailed guide. Step-by-step instructions and tips for efficient package management and system updates. #centlinux #linux #yum

Problem Statement

rpm command serves its purpose while installing individual packages, but it will become too difficult to install packages with hierarchical dependencies. At this point we can take advantage from yum command. Unfortunately, there is no yum repository configured in RHEL 7 servers by default, and to access to public yum repositories from Red Hat Network (RHN) you are required to have an Active Red Hat Subscription. However, we can utilize the contents of RHEL 7 ISO file to create a Local Yum Repository for our network.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

745772 0021

Setup Local Yum Repository in RHEL 7

Transfer the RHEL 7 ISO on the Server where we want to configure Local Yum Repository. I have already copied RHEL 7 ISO on the Server.

# ls rhel*
rhel-server-7.0-x86_64-dvd.iso

Create a directory and mount the ISO file on that directory.

# mkdir /mnt/iso
# echo "/root/rhel-server-7.0-x86_64-dvd.iso /mnt/iso iso9660 defaults 0 0" >> /etc/fstab
# mount -a
mount: /dev/loop0 is write-protected, mounting read-only

Now, RHEL 7 ISO has been persistently mounted at /mnt/iso. Let’s add Local Yum Repository now.

# cat >> /etc/yum.repos.d/localyum.repo << EOF
> [localyum]
> name=localyum
> baseurl=file:///mnt/iso
> enabled=1
> gpgcheck=0
> EOF

Build cache of our yum server.

# yum clean all
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: localyum
Cleaning up everything

# yum makecache
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localyum                                                                                           | 4.1 kB  00:00:00
(1/4): localyum/group_gz                                                                           | 134 kB  00:00:01
(2/4): localyum/filelists_db                                                                       | 3.0 MB  00:00:02
(3/4): localyum/primary_db                                                                         | 3.4 MB  00:00:01
(4/4): localyum/other_db                                                                           | 1.3 MB  00:00:00
Metadata Cache Created

Our Local yum repository has been configured successfully. Since, we want to use this Local yum repository for other servers as well, therefore, we use an FTP Server to share this repository to other servers in network.

Install FTP on RHEL 7

Install an FTP Server using newly configured yum repository.

# yum install -y vsftpd
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                    Arch                       Version                         Repository                    Size
==========================================================================================================================
Installing:
 vsftpd                     x86_64                     3.0.2-9.el7                     localyum                     166 k

Transaction Summary
==========================================================================================================================
Install  1 Package

Total download size: 166 k
Installed size: 343 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : vsftpd-3.0.2-9.el7.x86_64                                                                              1/1
  Verifying  : vsftpd-3.0.2-9.el7.x86_64                                                                              1/1

Installed:
  vsftpd.x86_64 0:3.0.2-9.el7

Complete!

Start and enable vsftpd service.

# systemctl start vsftpd.service ; systemctl enable vsftpd.service
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service'

Allow FTP service through Linux firewall.

# firewall-cmd --permanent --add-service=ftp ; firewall-cmd --reload
success
success

Now create a directory in /var/ftp/pub and change the mountpoint of ISO in /etc/fstab.

# cd /var/ftp/pub/
# mkdir iso
# sed -i 's//mnt/iso//var/ftp/pub/iso/g' /etc/fstab
# umount /mnt/iso
# mount -a
mount: /dev/loop0 is write-protected, mounting read-only

Change SELinux mode to permissive.

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux
# setenforce permissive

Configure Yum Clients

Now connect to another server and configure its yum repository.

# cat >> /etc/yum.repos.d/localyum.repo << EOF
> [localyum]
> name=localyum
> baseurl=ftp://192.168.116.11/pub/iso
> enabled=1
> gpgcheck=0
> EOF

# yum clean all
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: localyum
Cleaning up everything

# yum makecache
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localyum                                                                                           | 4.1 kB  00:00:00
(1/4): localyum/group_gz                                                                           | 134 kB  00:00:00
(2/4): localyum/filelists_db                                                                       | 3.0 MB  00:00:00
(3/4): localyum/primary_db                                                                         | 3.4 MB  00:00:00
(4/4): localyum/other_db                                                                           | 1.3 MB  00:00:00
Metadata Cache Created

We can now configure all RHEL 7 servers in our network to use this Local Yum Repository.

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Final Thoughts

Setting up a local Yum repository in RHEL 7 using an ISO file is a smart way to streamline package management and enhance system efficiency. By following this guide, you should now have a reliable local repository that accelerates software installation and updates.

If you need further assistance or tailored solutions for your Yum repository setup, I offer professional services to optimize your system configuration. Feel free to explore my Fiverr services for more details: VPS Server Administration. I’m here to ensure your repository is robust and seamlessly integrated!

Simplify package management with your local Yum repository today!

Leave a Reply