How to Create a Local Red Hat Repository

There are many reasons you may want a local Red Hat Enterprise Linux repository. Bandwidth is a major factor as downloading updates from the Internet can be time and bandwidth consuming. Another reason may be that your servers are not connected to the Internet and thus need to get their updates from a local source. You may have a development environment that you would prefer to not spend money on licenses for but still need to update. Whatever your reason, this tutorial will walk you through the process of getting your local repository setup.

Note: The server that serves as your repository should only serve as a repository.

Install packages needed for the repositories

yum install yum-utils createrepo httpd

Create the directories for your repositories

mkdir /var/www/html/rhel6
mkdir /var/www/html/rhel6/server
mkdir /var/www/html/rhel6/dts
mkdir /var/www/html/rhel6/dts2
mkdir /var/www/html/rhel6/rhsc

Helpful Commands

List the repos on your server both enabled and disabled.

yum repolist all

List the repos available on your subscription

subscription-manager repos --list

Enable a repo on your system

subscription-manager repos --enable=rhel-6-server-optional-rpms

Disable a repo on your system

subscription-manager repos --disble=rhel-6-server-optional-rpms

We want to have the server, dts, and rhsc (software collections) repositories enabled on the repository

Sync Repos

Once all of these repos have been enabled perform the following command for all of them changing the download_path for each to match the download_path for that repo.

reposync --gpgcheck -l --repoid=repoid --download_path=/var/www/html/rhel6/repo_name --downloadcomps --download-metadata

Note: The server repo will take the longest. Like all night long. The others should be much shorter.

Createrepo Command

Once the packages have been downloaded all that is needed is the createrepo command below for each repo

createrepo -v /var/www/html/rhel6/repo_name/ -g comps.xml

Note: The -g comps.xml is only needed for the server repo.

Setting Up Client Servers

Now you have a local repository but you need to make some changes on your Red Hat servers that will be using these repositories for updates.

First make sure that all other repos have the enabled flag set to 0 (zero) within the repo file in /etc/yum.repos.d. I wouldn't delete the repos for now because you might need them later. Simply changing the enabled flag is enough.

Now you need to create a .repo file that will be added to the /etc/yum.repos.d directory on every server using the repositories. That file should look similar to the following file.

vi /etc/yum.repos.d/name_of_repo_file.repo

[server]
name = rhel-6-server-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/server
gpgcheck = 0
enabled = 1

[dts]
name = rhel-server-dts-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts
gpgcheck = 0
enabled = 1

[dts2]
name = rhel-server-dts2-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts2
gpgcheck = 0
enabled = 1

[rhsc]
name = rhel-server-dts2-6-rpms
baseurl = http://hostname_or_ip_address_of_repository/rhel6/dts2
gpgcheck = 0
enabled = 1

Create Script and Cron Job to Update Your Repositories

Create a script named update-repository.sh and put it in /usr/local/bin with the following contents:

vi /usr/local/bin/update-repository.sh

echo Update script started at $(date) >> /var/log/update-repository.log
reposync --gpgcheck -l --repoid=rhel-6-server-rpms --download_path=/var/www/html/rhel6/server --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/server/
reposync --gpgcheck -l --repoid=rhel-server-dts-6-rpms --download_path=/var/www/html/rhel6/dts --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/dts/ \\
reposync --gpgcheck -l --repoid=rhel-server-dts2-6-rpms --download_path=/var/www/html/rhel6/dts2 --downloadcomps --download-metadata
createrepo --update /var/www/html/rhel6/dts2/
echo Update script ended at $(date) >> /var/log/update-repository.log

chmod 600 /usr/local/bin/update-repository.sh

Note that I have it dropped into a log that I have setup to rotate monthly.

Create a file in /etc/cron.d and name it update-repository with the following content.

vi /etc/cron.d/update-repository

@weekly root /usr/local/bin/update-repository.sh

Final Thoughts

There are many different ways to accomplish setting up a local repository and I certainly didn't invent the wheel on this one. Consult my sources below for more information and insight for your setup.

Sources

Share this page:

3 Comment(s)

Add comment

Comments

From: Fmo

I would strongly suggest to use createrepo_c as it is much faster and consumes a lot less memory.

From: christensen143

Thanks for the suggestion. I've actually never heard of createrepo_c before you mentioned and found some speed comparisons here:

https://fedorahosted.org/createrepo_c/wiki/SpeedComparison

It is significantly faster. I will have to test it out and get back to you on it. Thanks for the suggestion!

From: dude

or rsync from a mirror. no need to use create repo then. https://wiki.centos.org/HowTos/CreateLocalMirror