How To Create a Local Repository with mrepo on CentOS 6

Introduction

In this guide, you will set up a local CentOS repository for your internal network. Using a local repository has some advantages like saving network bandwidth or placing your custom RPMs.

Prerequisites

Before you begin this guide you'll need the following things:

  • epel-release
  • mrepo
  • httpd
  • screen

Step 1 - Installing EPEL repository

We need this repository for installing mrepo package. We can install it by running the following command.

EPEL package is included in CentOS Extras repository which is enabled by default in CentOS 6.

yum install epel-release

The other packages will be installed from CentOS repository.

Step 2 - Installing the packages

Now we can install the rest of the packages we need for configuring the local repository.

yum install mrepo httpd lftp screen

Disable all EPEL repositories after that. Usually third party repository contains a newer version of a core package than the Red Hat repository and this could lead to many problems afterwards.

You can enable the repository again during of yum install command with yum --enablerepo=epel install <package>

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel*

Another way to prevent this would be to install yum-plugin-protectbase

Step 3 - Configuring mrepo

The main configuration file for mrepo is /etc/mrepo.conf. The example file from /usr/share/doc/mrepo-0.8.7/mrepo-example.conf gives an overview of all settings that can be applied to main configuration.

[main]
srcdir = /repository/mrepo
wwwdir = /repository/www/mrepo
confdir = /etc/mrepo.conf.d
arch = x86_64
logfile = /var/log/mrepo.log

Here are the important lines from the configuration file

  • srcdir - the location for RPMs files, you may use a separate disk/LV just for the repo.
  • wwwdir - the location of the generated repositories.
  • confdir - does not need to be modified, here we'll create the configuration files for each repository.
  • arch - replace i386 with x86_64 if this is not needed
  • logfile - default configuration files does not come with this parameter so we need to add it.

Examples for some of the distributions can be found at /usr/share/doc/mrepo-0.8.7/dists. Let's go ahead and create the configuration file for CentOS 6 and 7. Choose the fastest server from this location.

vi /etc/mrepo.conf.d/centos6_x86_64.conf

[centos6]
name = CentOS $release ($arch)
release = 6
arch = x86_64
metadata = yum repomd

os = http://ftp.upcnet.ro/distros/centos/$release/os/$arch/Packages/
updates = http://ftp.upcnet.ro/distros/centos/$release/updates/$arch/Packages/
extras = http://ftp.upcnet.ro/distros/centos/$release/extras/$arch/Packages/
fasttrack = http://ftp.upcnet.ro/distros/centos/$release/fasttrack/$arch/Packages/
contrib = http://ftp.upcnet.ro/distros/centos/$release/contrib/$arch/Packages/
centosplus = http://ftp.upcnet.ro/distros/centos/$release/centosplus/$arch/Packages/

Here is an example for CentOS 7

vi /etc/mrepo.conf.d/centos7_x86_64.conf

[centos7]
name = CentOS $release ($arch)
release = 7
arch = x86_64
metadata = yum repomd

os = http://ftp.upcnet.ro/distros/centos/$release/os/$arch/Packages/
updates = http://ftp.upcnet.ro/distros/centos/$release/updates/$arch/Packages/
extras = http://ftp.upcnet.ro/distros/centos/$release/extras/$arch/Packages/
fasttrack = http://ftp.upcnet.ro/distros/centos/$release/fasttrack/$arch/Packages/
contrib = http://ftp.upcnet.ro/distros/centos/$release/contrib/$arch/Packages/
centosplus = http://ftp.upcnet.ro/distros/centos/$release/centosplus/$arch/Packages/

Step 4 - Initial sync

Everything is setup now so we can begin the initial sync for our local repositories.

It takes awhile to synchronize all packages therefore run the following commands under screen. The process will continue running even if the session gets disconnected.

mrepo -g -u -vvv centos6 && mrepo -g -u -vvv centos7

Hit "ctrl+a" then "d" to exit screen and leave the session running in background.

Step 5 - Enable mrepo daily cron job

Just comment out the line

vi /etc/cron.d/mrepo

30 2 * * * root /usr/bin/mrepo -q -ug

Step 6 - Apache configuration

Edit /etc/httpd/conf.d/mrepo.conf and add the following lines

vi /etc/httpd/conf.d/mrepo.conf

AddDescription "CentOS 6 for x86_64" centos6-x86_64
AddDescription "CentOS 7 for x86_64" centos7-x86_64

Enable and start httpd

chkconfig httpd on

/etc/init.d/httpd start