Create your own local Redhat Package Repo Cache

If you manage a bunch of Redhat Enterprise Linux servers (RHEL), it can be wasteful or difficult to update packages from the internet each time (or you don’t have enough subscriptions). So let’s create a package repository on a local server which will update every night and allow the other internal servers to access it. This is particularly useful if only one server on your network has internet access or you have a slower connection.

NOTE: You will need a good amount of storage space to do this. I suggest 1TB at minimum. Also create a separate partition just for the web server and rpm files.

Here are some articles that go into more detail on each option:

Can update RPMs from DVD: RPM DVD

Cam update RPMs from a server that has internet access: RPM Internet

Other update options (run own yum server, etc): Update Options

Nice 2 page PDF Yum Cheat Sheet: Yum Commands

Setup the local Redhat repository server

  • ¬†Setup the repo server first by creating a subscription and selecting the pool of updates. Change the username to your Redhat account, and change the pool_id_from_above (a string of random numbers and letters) to the output give from the command above it.

  • Now enable all the repositories that you will need (at least for now). The repo from this example is: “rhel-7-server-rpms” which covers the majority of packages for RHEL 7.x and is enabled by default. To get a list of repos available, look at the “/etc/yum.repos.d/redhat.repo” file or run “yum repolist all”. There is a section for each repo (the repo name starts with a bracket [¬† ) in that file. There are a lot of them!

  • To enable a specific repo for your master machine that you found in that list:

  • Great, now we have the repository locally enabled, lets add a web server so other machines can download them through http. Installing Apache is outside the realm of this tutorial, we can install nginx real pretty easily. You can read more on it here:

Install a Web Server – Nginx

  • Once installed, we need to allow the local firewall to give access to the web server.

  • Don’t forget to edit your index.html with some useful information. You can turn on directory listing if you want to be nice.
  • Now that we have identified all the repositories and have a web server, lets download all the files in one. This will be our local cache. Make sure to put this on a separate partition so you don’t max out a system or root partition. This part will take awhile as it is about 35GB at the time of writing (Feb 2019).

  • Now the fun part, let’s configure the repository so it’s all Redhat-y. This involves installing createrepo. This program creates the repo database that yum needs. It might take awhile.

  • That is it for the server side of things. Make sure you can browse to your server (http://server_ip) and see the package repo.

Setup the local clients

  • Now for each client that you want to use this repo server, we have to add a .repo file to them which points to our internal server/ip
  • You will have to duplicate this configuration for each repo that is enabled, you can use the same file or multiple files to keep is more organized.
  • Here is the example for our rhel-7-server-rpms repo, replace 192.168.1.100 with your internal ip address or FQDN. Read more here: Redhat

  • Now we need to let yum update and test it out

Keeping your repository server up to date

The best bet is to create a cron script that runs the reposync and createrepo commands each night when bandwidth is low. Just run the same commands as above and update permissions. I also suggest using the timeout command which kills anything that doesn’t finish by the alloted time. This way you don’t have 10 scripts all trying to sync over each other if they don’t finish.

 

 

 

 

Leave a Comment