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.

[root@centos7 ~]# yum install epel-release

And then Nginx.

[root@centos7 ~]# yum install nginx

Start and enable Nginx.

[root@centos7 ~]# systemctl start nginx
[root@centos7 ~]# systemctl enable nginx

Install and configure a local firewall.

[root@centos7 ~]# yum install firewalld
[root@centos7 ~]# systemctl enable firewalld
[root@centos7 ~]# systemctl start firewalld
[root@centos7 ~]# firewall-cmd --zone=public --permanent --add-service={http,https}
[root@centos7 ~]# firewall-cmd --reload
[root@centos7 ~]# 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.

[apike@workpc ~]$ curl -s rhel01.pikedom.com | grep Welcome
        
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>

Create a virtual host entry for Nginx.

[root@centos7 ~]# vim /etc/nginx/conf.d/rhel01.pikedom.com.conf

….with:

server {
        listen   80;
        server_name  rhel01.pikedom.com;
        root   /var/www/vhosts/rhel01.pikedom.com/public_html;
        location / {
                index  index.php index.html index.htm;
                autoindex on;	#enable listing of directory index
        }
}

Create the directory structure:

[root@centos7 ~]# mkdir -pv /var/www/vhosts/rhel01.pikedom.com/public_html

Check for configuration errors and restart Nginx.

[root@centos7 ~]# nginx -t
[root@centos7 ~]# systemctl restart nginx

Local Yum Repository

[root@repo ~]# yum install createrepo yum-utils -y

Create directories structure.

[root@centos7 ~]# mkdir -pv /var/www/vhosts/rhel01.pikedom.com/public_html/{base,centosplus,extras,updates}

Now use reposync to synchronise the CentOS yum repository.

[root@centos7 ~]# reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/
[root@centos7 ~]# reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/
[root@centos7 ~]# reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/
[root@centos7 ~]# reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/

Now create new repository data:

[root@centos7 ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/base/
[root@centos7 ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/centosplus/comps.xml
[root@centos7 ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/centosplus/
[root@centos7 ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/extras/comps.xml
[root@centos7 ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/extras/
[root@centos7 ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/updates/comps.xml
[root@centos7 ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/updates/

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.

[root@centos7 ~]# vim update-local-mirror

…contents:

#!/bin/bash

# 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/rhel01.pikedom.com/public_html/

if [ $REPO = 'base' ]
  then
    createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/$REPO/  
  else
    createrepo /var/www/vhosts/rhel01.pikedom.com/public_html/$REPO/  
fi
done

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

[root@centos7 ~]# chmod -v 755 update-local-mirror
[root@centos7 ~]# 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