Host your Own Yum Repository

Here we create our own yum repository on a fresh up-to-date installation of Centos 7.

Configure Nginx

First install the EPEL repository.

[[email protected] ~]# yum install epel-release

And then Nginx.

[[email protected] ~]# yum install nginx

Start and enable Nginx.

[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl enable nginx

Install and configure a local firewall.

[[email protected] ~]# yum install firewalld
[[email protected] ~]# systemctl enable firewalld
[[email protected] ~]# systemctl start firewalld
[[email protected] ~]# firewall-cmd --zone=public --permanent --add-service={http,https}
[[email protected] ~]# firewall-cmd --reload
[[email protected] ~]# reboot

Once back online and from another machine, check the URL or IP is accessible. You can use a browser or curl as shown below.

[[email protected] ~]$ curl -s | grep Welcome
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>

Create a virtual host entry for Nginx.

[[email protected] ~]# vim /etc/nginx/conf.d/


server {
        listen   80;
        root   /var/www/vhosts/;
        location / {
                index  index.php index.html index.htm;
                autoindex on;	#enable listing of directory index

Create the directory structure:

[[email protected] ~]# mkdir -pv /var/www/vhosts/

Check for configuration errors and restart Nginx.

[[email protected] ~]# nginx -t
[[email protected] ~]# systemctl restart nginx

Local Yum Repository

[[email protected] ~]# yum install createrepo yum-utils -y

Create directories structure.

[[email protected] ~]# mkdir -pv /var/www/vhosts/{base,centosplus,extras,updates}

Now use reposync to synchronise the CentOS yum repository.

[[email protected] ~]# reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/vhosts/
[[email protected] ~]# reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/vhosts/
[[email protected] ~]# reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/vhosts/
[[email protected] ~]# reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/vhosts/

Now create new repository data:

[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/
[[email protected] ~]# touch /var/www/vhosts/
[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/
[[email protected] ~]# touch /var/www/vhosts/
[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/
[[email protected] ~]# touch /var/www/vhosts/
[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/

Check you can browse to your new repository.

Cron Job to Synchronise Repository

To keep our repository up-to-date, we need to create a cronjob.

[[email protected] ~]# vim update-local-mirror



# specify all local repositories in a single variable
LOCAL_REPOS='base centosplus extras updates'

# a loop to update repos one at a time 

for REPO in ${LOCAL_REPOS}; do
  reposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=/var/www/vhosts/

if [ $REPO = 'base' ]
    createrepo -g comps.xml /var/www/vhosts/$REPO/  
    createrepo /var/www/vhosts/$REPO/  

Make it executable and move the file to /etc/cron.daily/:

[[email protected] ~]# chmod -v 755 update-local-mirror
[[email protected] ~]# mv update-local-mirror /etc/cron.daily/

You should now have a working yum mirror site. I’ll create another post on how to configure another CentOS/RHEL device as a client.

Be the first to comment

Leave a Reply