Host a yum (dnf) repository locally and share it with other server by NFS

See how to prepare your Centos8 environment

da lin
2 min readOct 13, 2020

For security consideration in big corporation, the linux packages repository are always hosted internally instead of using public repository from internet. This article focus on how to host yum repository locally and how to share the repository by NFS.

Setup a yum repository locally

The tutorials on how to make the setup can be found anywhere. Just put a simple way for usage by myself. This approche can be easily extended for advanced usage.

Remove the default repos created by Centos8’s installation (please skip if you don’t need to do so)

$ sudo rm -rf /etc/yum.repos.d/*

Create a new repo (e.g. lintech.repo) file with following content

[BaseOS]
name=BaseOS
baseurl=file:///repo/BaseOS
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///repo/AppStream
gpgcheck=0

Create local folder which contains repositories

$ sudo mkdir /repo

Now we can put any repo which contains two folders: packages & repodata, but here I’ll mount the default repos provided by centos ISO

  • Insert ISO from
  • Change boot order by taking Hard Drive in priority
  • Add /dev/sr0 /repo iso9660 defaults 0 0 into /etc/fstab and execute sudo mount -a
  • Then use yum repolist to see newly added repos can be found

Share the repository with other servers in same network by NFS

Now, we can start sharing the folder /repo by using NFS.

  • Install nfs service: $ sudo yum install -y nfs-utils
  • Add new line /repo *(ro,no_root_squash) into file /etc/exports
  • Enable & start nfs service: $ sudo systemctl enable --now nfs-server
  • Allow nfs: $ sudo firewall-cmd --add-service nfs --permanent
  • Allow rpc-bind: $ sudo firewall-cmd --add-service rpc-bind --permanent
  • Allow mountd: $ sudo firewall- cmd --add-service mountd --permanent
  • Reload firewall: $ sudo firewall-cmd --reload
  • Use command: $ showmount -e localhost to check the export configurations, the result should looks like:

Export list for centos-repo-server.lintech.sg:
/repo *

Now ssh to another server which is in the same network as the NFS server

  • Install nfs support: $ sudo yum install nfs-utils
  • Empty default repos created by centos: $ sudo rm -rf /etc/yum.repo.d/*
  • Create folder: $ sudo mkdir /repo
  • Add line [centos-repo-server]:/repo /repo nfs sync 0 0 into /etc/fstab
  • Reload mount: $ sudo mount -a
  • Add repo file (e.g. /etc/yum.repo.d/lintech.repo) with the following content, then use yum repolist to check the new repos:

[BaseOS]
name=BaseOS
baseurl=file:///repo/BaseOS
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///repo/AppStream
gpgcheck=0

--

--

No responses yet