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

[[email protected] ~]# mkdir -pv /var/www/vhosts/rhel01.pikedom.com/public_html

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/rhel01.pikedom.com/public_html/{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/rhel01.pikedom.com/public_html/
[[email protected] ~]# reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/
[[email protected] ~]# reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/vhosts/rhel01.pikedom.com/public_html/
[[email protected] ~]# 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:

[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/base/
[[email protected] ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/centosplus/comps.xml
[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/centosplus/
[[email protected] ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/extras/comps.xml
[[email protected] ~]# createrepo -g comps.xml /var/www/vhosts/rhel01.pikedom.com/public_html/extras/
[[email protected] ~]# touch /var/www/vhosts/rhel01.pikedom.com/public_html/updates/comps.xml
[[email protected] ~]# 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.

[[email protected] ~]# 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/:

[[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