How to create a local repo in Rocky Linux 8.

Install nginx. Enable service.

<pre lang="bash">
dnf install nginx
systemctl enable nginx --now
systemctl status nginx

Create repo.

<pre lang="bash">
dnf repolist
dnf install createrepo yum-utils
mkdir /usr/share/nginx/html/repos
mkdir -p /usr/share/nginx/html/repos/{baseos,appstream}

Sync repos.

<pre lang="bash">
dnf reposync -g --delete -p /usr/share/nginx/html/repos/ --repoid=baseos --newest-only --download-metadata
dnf reposync -g --delete -p /usr/share/nginx/html/repos/ --repoid=appstream --newest-only --download-metadata
createrepo /usr/share/nginx/html/repos/baseos/
createrepo /usr/share/nginx/html/repos/appstream/

Create cron to sync repos daily. Create file called /etc/cron.daily/update-localrepos

<pre lang="bash">
#!/bin/bash
/bin/dnf reposync -g --delete -p /usr/share/nginx/html/repos/ --repoid=baseos --newest-only --download-metadata
/bin/dnf reposync -g --delete -p /usr/share/nginx/html/repos/ --repoid=appstream --newest-only --download-metadata
/usr/bin/createrepo /usr/share/nginx/html/repos/baseos/
/usr/bin/createrepo /usr/share/nginx/html/repos/appstream/

Create a file called /etc/nginx/conf.d/repos.conf.

<pre lang="bash">
server {
        listen   80;
        server_name  reposerver.example.com;
        root   /usr/share/nginx/html/repos;
	index index.html; 
	location / {
                autoindex on;
        }
}

Restart nginx.

<pre lang="bash">
systemctl restart nginx

Configure firewall and SELinux.

<pre lang="bash">
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload
getenforce
chcon -Rt httpd_sys_content_t /usr/share/nginx/html/repos/

Move existing repos to /tmp.

<pre lang="bash">
mv /etc/yum.repos.d/*.repo /tmp/

Create a new repo called /etc/yum.repos.d/localrepo.repo

<pre lang="bash">
[localrepo-base]
name=RockyLinux Base
baseurl=http://reposerver.example.com/baseos/
gpgcheck=0
enabled=1
[localrepo-appstream]
name=RockyLinux Base
baseurl=http://reposerver.example.com/appstream/
gpgcheck=0
enabled=1

Clean cache and check repolist.

<pre lang="bash">
dnf clean all 
dnf repolist

Edit /etc/hosts and add reposerver.example.com. Add it to other hosts.

<pre lang="bash">
echo "10.10.10.10        reposerver.example.com     reposerver" >> /etc/hosts

Finally, run yum install against the local repo. Installing lvm in this example.

<pre lang="bash">
yum install lvm2