You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this guide we’ll explore how you can create Local repositories of CentOS 8 by using Rsync and hosting them with Nginx web server. The Local CentOS 8 mirrors are created by having a Local cron job which regularly checks for updates in the upstream repositories and update them locally accordingly.

By Creating CentOS 8 Local repository mirrors, you’ll be able to configure your CentOS 8 servers to access packages without the need for internet access. This will improve your security and reduces the amount of bandwidth consumed by pulling RPM packages from external sources.

In this setup, we’ll use a CentOS 7 or CentOS 8 server to perform the actions. You should have an external storage with enough capacity to host repository packages and potential growth.

For CentOS 7 & CentOS 6, check: How To Create Local CentOS 7 6 & EPEL Repository Sync Mirrors

Step 1: Install Nginx Web Server

As Nginx is used as a web server of choice, install it in your CentOS 7 system.

CentOS 8

sudo dnf -y install @nginx

CentOS 7:

sudo yum -y install epel-release
sudo yum -y install nginx

After installation, start and enable the service.

sudo systemctl enable --now nginx

Confirm that the service is running.

$ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-11-01 00:28:39 EAT; 4s ago
  Process: 7378 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 7376 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 7375 ExecStartPre=/usr/bin/rm -f /run/ (code=exited, status=0/SUCCESS)
 Main PID: 7380 (nginx)
    Tasks: 2 (limit: 11512)
   Memory: 9.4M
   CGroup: /system.slice/nginx.service
           ├─7380 nginx: master process /usr/sbin/nginx
           └─7381 nginx: worker process

Nov 01 00:28:39 centos8.novalocal systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 01 00:28:39 centos8.novalocal nginx[7376]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 01 00:28:39 centos8.novalocal nginx[7376]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 01 00:28:39 centos8.novalocal systemd[1]: nginx.service: Failed to parse PID from file /run/ Invalid argument
Nov 01 00:28:39 centos8.novalocal systemd[1]: Started The nginx HTTP and reverse proxy server.

Open http port in the firewall.

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

Step 2: Create Repository directories

I have a secondary disk in my server that will be used to store repository data – /dev/vdc of 100GB.

$ lsblk 
vda         252:0    0  20G  0 disk 
├─vda1      252:1    0   1G  0 part /boot
└─vda2      252:2    0   9G  0 part 
  ├─cl-root 253:0    0   8G  0 lvm  /
  └─cl-swap 253:1    0   1G  0 lvm  [SWAP]
vdc         252:32   0  100G 0 disk 

I’ll create a partition on this block device and mount it under the /data directory. Let’s start by creating a partition on it.

sudo parted -s -a optimal -- /dev/vdc mklabel gpt
sudo parted -s -a optimal -- /dev/vdc mkpart primary 0% 100%
sudo parted -s -- /dev/vdc align-check optimal 1

Create a physical volume and volume group in it.

$ sudo pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.

$ sudo vgcreate data /dev/vdc1
 Volume group "data" successfully created

Create a Logical volume

$ sudo lvcreate -n repos -l+100%FREE data
Logical volume "repos" created.

Create a file system

$ sudo mkfs.xfs /dev/mapper/data-repos
meta-data=/dev/mapper/data-repos isize=512    agcount=4, agsize=1965824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=7863296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=3839, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Create directory for mounting the Logical volume.

sudo mkdir /data

Create a mount point

$ sudo vim /etc/fstab

/dev/mapper/data-repos /data xfs defaults 0 0 

Mount it.

sudo mount -a


$ df -hT /data
Filesystem             Type  Size   Used   Avail Use% Mounted on
/dev/mapper/data-repos xfs   100G   247M   100G   1%  /data

Create base directory for CentOS 8 repository data.

sudo mkdir -p /data/repos/centos/8/

Confirm all directories are created.

$ tree /data/
└── repos
    └── centos
        └── 8

3 directories, 0 files

Step 3: Create Repositories Sync script

Let’s now create a script that will be used to sync contents from the remote repositories to our local system.

$ sudo vim /etc/

Paste below data.


# Start sync if base repo directory exist
if [[ -d "$repos_base_dir" ]] ; then
  # Start Sync
  rsync  -avSHP --delete rsync://  "$repos_base_dir"
  # Download CentOS 8 repository key
  wget -P $repos_base_dir wget

Make the script executable.

sudo chmod +x /etc/

Install Tmux and initiate first execution.

$ sudo yum -y install tmux
$ tmux
$ sudo /etc/

The script should start running.

sync centos 8 repositories

A number of directories should be created.

$ ls -1 /data/repos/centos/8/

Wait for the initial script to finish running then create a cron job for weekly sync.

sync centos 8 repositories completed

I’ll set my sync to run every Sunday 6pm.

$ sudo crontab -e

00 18 * * 7  /etc/

Step 4: Configure Nginx

Create Nginx configuration file to serve the repository contents.

$ sudo vim /etc/nginx/conf.d/centos.conf
server {
	listen 80;
        root /data/repos/;

       location / {
                autoindex on;
  • Where is the domain name you’ll use to access the repositories.

Configure SELinux Labels.

sudo semanage fcontext -a -t httpd_sys_content_t "/data/repos(/.*)?"
sudo restorecon -Rv /data/repos

Restart nginx after the change.

sudo nginx -t
sudo systemctl restart nginx

Open the server URL to confirm it is working.

centos8 local repositories

Step 5: Configure CentOS 8 Client machines

Now that our mirror is ready, we can configure our CentOS 8 machines to use the local repositories.

Start by backing up current repositories

cd /etc/yum.repos.d/
sudo mkdir old-repos
sudo mv *.repo old-repos 

Create a new repository file

sudo vim local.repo

Modify below and paste it.

name=CentOS-$releasever - Base

name=CentOS-$releasever - AppStream

name=CentOS-$releasever - Plus

name=CentOS-$releasever - Extras

name=CentOS-$releasever - PowerTools

name=CentOS-$releasever - cr

name=CentOS-$releasever - fasttrack


  • is the Domain used for repos access

Clean current repo cache:

sudo yum clean all

The update:

$ sudo yum makecache
CentOS-8 - AppStream                                                                                               1.2 MB/s | 4.3 kB     00:00    
CentOS-8 - Base                                                                                                    3.9 kB/s | 3.9 kB     00:01    
CentOS-8 - Extras                                                                                                  881 kB/s | 1.5 kB     00:00    
Metadata cache created.

List repositories:

$ sudo yum repolist 
Last metadata expiration check: 0:02:10 ago on Fri 01 Nov 2019 12:41:38 PM EAT.
repo id                                                          repo name                                                                   status
AppStream                                                        CentOS-8 - AppStream                                                        5,089
BaseOS                                                           CentOS-8 - Base                                                             2,843
extras                                                           CentOS-8 - Extras                                                               3

Run system update from it.

sudo yum -y update

Step 6: Enabling Disabled repositories

Some repositories are disabled by default. To enable them, install yum-utils package.

sudo yum install yum-utils

To activate the repository, use the command:

sudo yum-config-manager --enable reponame

Below are the examples to enable PowerTools and centosplus repositories:

sudo yum-config-manager --enable PowerTools
sudo yum-config-manager --enable centosplus


$ sudo yum repolist 
CentOS-8 - AppStream                                                                                               1.7 MB/s | 4.3 kB     00:00    
CentOS-8 - Base                                                                                                    2.0 MB/s | 3.9 kB     00:00    
CentOS-8 - PowerTools                                                                                               75 MB/s | 1.8 MB     00:00    
CentOS-8 - Plus                                                                                                     58 MB/s | 833 kB     00:00    
CentOS-8 - Extras                                                                                                  783 kB/s | 1.5 kB     00:00    
repo id                                                          repo name                                                                   status
AppStream                                                        CentOS-8 - AppStream                                                        5,089
BaseOS                                                           CentOS-8 - Base                                                             2,843
PowerTools                                                       CentOS-8 - PowerTools                                                       1,507
centosplus                                                       CentOS-8 - Plus                                                                26
extras                                                           CentOS-8 - Extras                                                               3

To disable, substitute –enable with –disable.

You now have working Local CentOS 8 Mirrors. Enjoy and check a similar guide we have for users running Satellite / Katello / Foreman.

How To Sync CentOS 8 repositories on Satellite / Katello / Foreman


  • Setup CentOS 8 repository
  • How to create CentOS 8 mirrors
  • How to host CentOS 8 repositories locally
  • Setup Local CentOS 8 Yum Repository
You can support us by downloading this article as PDF from the Link below. Download the guide as PDF