Summary

  Subject:

DNF Repository Server

  Updated:

2023-09-03

  Author:

Tim Hammond ([email protected])

Derek Pasnick ([email protected])

  Operating Systems:

Rocky 8

  Background:

This guide was written to create a dnf local mirror repo.

 

Table of Contents

VM Config

VM Specifications:

  • CPU: 1vCPU (2 cores)
  • RAM: 2 GB
  • HD: 100 GB

Change the hostname:

sudo hostnamectl set-hostname dnf01.domain.local

Update the IP:

sudo sed -i 's/192.168.30.199/192.168.30.114/g' /etc/sysconfig/network-scripts/ifcfg-ens192 sudo cat /etc/sysconfig/network-scripts/ifcfg-ens192

Install

Install the pre-reqs:

sudo dnf -y install httpd createrepo dnf-utils cronie

Enable the services to start automagically:

sudo systemctl enable httpd sudo systemctl enable crond

Start the services:

sudo systemctl start httpd sudo systemctl start crond

Add firewall rules:

sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload sudo firewall-cmd --list-all

Create the repo paths:

sudo mkdir -p /var/www/html/pub/rocky/8/AppStream/x86_64/os sudo mkdir -p /var/www/html/pub/rocky/8/BaseOS/x86_64/os sudo mkdir -p /var/www/html/pub/rocky/8/extras/x86_64/os

The following command will reach out and download copies of the official repositories. "newest-only" will help to keep the repository size mangeable.

Only download the latest package version: --newest-only
Download non-default metadata: --download-metadata
Specifies the location to save the packages: -p
Specify repository ID: --repo

sudo reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/AppStream/x86_64/os/ --repo=appstream sudo reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/BaseOS/x86_64/os/ --repo=baseos sudo reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/extras/x86_64/os/ --repo=extras

Create the Repo

createrepo is not required for Rocky 8. reposync will download everything including the repodata. sudo createrepo /var/www/html

Setup CROBTAB

In this section, we will create a cron job to update the repos.

OPTIONAL:

If there is a cron.allow file, then the user or users that need to use cron will need to be listed in the file. You can use cron.deny to explicitly disallow certain users from using cron. If neither files exist, then only the super user is allowed to run cron.

Add the user names, one user name per line.

Change the email address where cron output is sent.

sudo sed -i 's/MAILTO=root/[email protected]/g' /etc/crontab sudo cat /etc/crontab | grep -i MAILTO

Cronie should have already been installed earlier. To list cron jobs, type:

sudo crontab -l

To list cron jobs for a user, type:

sudo crontab -l -u root sudo crontab -l -u localadmin

To add new jobs, use the command below. This will use the default editor. By using sudo, this will add the jobs to the root accounts cronjob. As a result, using sudo in the actual commands is not necessary.

sudo crontab -e

The following commands will schedule a cron job to update the directory daily at 3am and in 30min incruments every Monday. The format is as follows: minute hour day month day_of_week username command

00 3 * * mon reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/AppStream/x86_64/os/ --repo=appstream 30 3 * * mon reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/BaseOS/x86_64/os/ --repo=baseos 00 4 * * mon reposync --newest-only --download-metadata -p /var/www/html/pub/rocky/8/extras/x86_64/os/ --repo=extras

NOTE:

See the "createrepo" note above schedule a cron job to update the repo database after the regularly scheduled cron job finishes.
00 5 * * mon createrepo --update /var/www/html

Client Setup

For the love of all that is holy, make a backup.

sudo cp /etc/yum.repos.d/Rocky-AppStream.repo /etc/yum.repos.d/Rocky-AppStream.repo.bak sudo cp /etc/yum.repos.d/Rocky-BaseOS.repo /etc/yum.repos.d/Rocky-BaseOS.repo.bak sudo cp /etc/yum.repos.d/Rocky-Extras.repo /etc/yum.repos.d/Rocky-Extras.repo.bak

The following lines will comment out the "mirrorlist." This way the defaults can be easily restored.

sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/Rocky-AppStream.repo sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/Rocky-BaseOS.repo sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/Rocky-Extras.repo

The following lines are appended to the bottom of the respective *.repo configs. These can be commented to easily restore the defaults.

sudo echo "baseurl=http://dnf01.domain.local/\$contentdir/\$releasever/AppStream/\$basearch/os/appstream/" | sudo tee -a /etc/yum.repos.d/Rocky-AppStream.repo sudo echo "baseurl=http://dnf01.domain.local/\$contentdir/\$releasever/BaseOS/\$basearch/os/baseos/" | sudo tee -a /etc/yum.repos.d/Rocky-BaseOS.repo sudo echo "baseurl=http://dnf01.domain.local/\$contentdir/\$releasever/extras/\$basearch/os/extras/" | sudo tee -a /etc/yum.repos.d/Rocky-Extras.repo

Verify repo setup

dnf repolist

References