Tuesday 1 March 2022

How to Configure Local Synced YUM repository on CentOS 7 using NGINX



YUM (YellowDog Updater Modified) is a package management tool for RPM based Linux system that helps to install, uninstall, and update packages. Local yum repository is used to save bandwidth, fasten package installations, network installations and systems updates for n numbers of systems in a local area network.

This article describes How to Configure Local Synced YUM repository on CentOS 7 using NGINX Web Server.

Step 1. Install NGINX Web Server: Follow the article How to Install NGINX Web Server on CentOS 7.

Step 2. Configure Local Yum Repo: Run the following command to install packages to manage repo:

[root@linuxcnf ~]# yum install yum-utils createrepo -y
Loaded plugins: fastestmirror
…………………….
Installed:
  createrepo.noarch 0:0.9.9-28.el7      yum-utils.noarch 0:1.1.31-54.el7_8
 
Complete!
[root@linuxcnf ~]#

Step 3. Sync Repository Data: Run the following command to sync the repository from CentOS repository:

[root@linuxcnf ~]# mkdir –p /var/www/html/base
[root@linuxcnf ~]# reposync --gpgcheck -l --repoid=base --newest-only --download_path=/var/www/html/base/
Loaded plugins: fastestmirror
…………………..
[root@linuxcnf ~]#
 
[root@linuxcnf ~]# mkdir –p /var/www/html/extras
[root@linuxcnf ~]# reposync --gpgcheck -l --repoid=extras –newest-only --download_path=/var/www/html/extras/
Loaded plugins: fastestmirror
……………………..
[root@linuxcnf ~]#
 
[root@linuxcnf ~]# mkdir –p /var/www/html/updates
[root@linuxcnf ~]# reposync --gpgcheck -l --repoid=updates --newest-only --download_path=/var/www/html/updates/
Loaded plugins: fastestmirror
……………………..
[root@linuxcnf ~]#
 
Step 4. Update Repository: Run the following commands to update and create metadata for local repository:

[root@linuxcnf ~]# createrepo /var/www/html/base/
Spawning worker 0 with 10072 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@linuxcnf ~]#
 
[root@linuxcnf ~]# createrepo /var/www/html/extras/
Spawning worker 0 with 277 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@linuxcnf ~]#
 
[root@linuxcnf ~]# createrepo /var/www/html/updates/
Spawning worker 0 with 1508 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@linuxcnf ~]#

Step 5. Configure NGINX Service: Open NGINX configuration file. Find “server {” section and replace root path /usr/share/nginx/html with /var/www/html. Add the location as well after the root directory till closed curly brackets:

[root@linuxcnf ~]# vi /etc/nginx/nginx.conf
…………………….
        root         /var/www/html;
        location /{
                index index.php index.html index.htm;
                autoindex on;
        }
…………………….
    Options All Indexes FollowSymLinks
…………………….
[root@linuxcnf ~]#

Step 6. Restart NGINX Service: Run the following command to restart the service to reflect the changes:

[root@linuxcnf ~]# systemctl restart nginx
[root@linuxcnf ~]#
 
Step 7. Create Firewall Rule: Run the following command to create rule in firewall to allow NGINX service:

[root@linuxcnf ~]# firewall-cmd --zone=public --permanent --add-service=http
success
[root@linuxcnf ~]# firewall-cmd --reload
success
[root@linuxcnf ~]#

Step 8. Verify the Configuration: Configure the repository on client as below and validate if it is working or not. Move all the exiting repo files from the location /etc/yum.repos.d/ to other location and create a new file with the below contents:

[root@linuxcnf ~]# vi /etc/yum.repos.d/mylocal.repo
[mylocalrepo-Base]
name=Local Sync Base Repo
baseurl=http://192.168.1.104/base/
gpgcheck=0
enabled=1
 
[mylocalrepo-Extras]
name=Local Sync Extras Repo
baseurl=http://192.168.1.104/extras/
gpgcheck=0
enabled=1
 
[mylocalrepo-Updates]
name=Local Sync Updates Repo
baseurl=http://192.168.1.104/updates/
gpgcheck=0
enabled=1

Save the file and finally Run the below command to check the repo status:

[root@linuxcnf ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: mylocalrepo-Base mylocalrepo-Extras mylocalrepo-Updates
Other repos take up 129 M of disk space (use --verbose for details)
[root@linuxcnf ~]#
 
[root@linuxcnf ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
mylocalrepo-Base                                         | 2.9 kB     00:00
mylocalrepo-Extras                                       | 2.9 kB     00:00
mylocalrepo-Updates                                      | 2.9 kB     00:00
(1/3): mylocalrepo-Extras/primary_db                       | 135 kB   00:00
(2/3): mylocalrepo-Updates/primary_db                      | 1.9 MB   00:00
(3/3): mylocalrepo-Base/primary_db                         | 6.0 MB   00:01
repo id                            repo name                              status
mylocalrepo-Base                   Local Sync Base Repo                   10,072
mylocalrepo-Extras                 Local Sync Extras Repo                    277
mylocalrepo-Updates                Local Sync Updates Repo                 1,508
repolist: 11,857
[root@linuxcnf ~]#
 
Done!!! Local yum Repositories is configured using NGINX and synced with CentOS 7 base repository data on CentOS 7. Run the repo sync command on periodically to sync the data.

No comments:

Post a Comment