How to build a local Yumrepo Server

part 1 of 4

Posted by paul on 2015.03.16

How to build a local Yumrepo Server - part 1 of 4

2015.03.16 Mon

  1. Part 1: Intro
  2. Part 2: Yumrepo 6.6basic - RPMs from DVDs only
  3. Part 3: Yumrepo 6.6 - exact mirror of a full Yumserver
  4. Part 4: How to use yumupdate.sh

Overview

Using a local yumrepo server will save you time and bandwidth when updating/installing RPMs on your CentOS servers, even if you have just a few to manage. You will also have a better control on the yum update process (such as controlling when you update your CentOS servers from v6.5 to v6.6). However setting it up can be time consuming.

My first blog on setting up yumrepo server (http://paulcodr.co/blog/2014/yumrepo-server-local/) was for CentOS 6.5, but it wasn't very well though out. When CentOS 6.6 was released, my yumrepo server stopped working, mainly because directory 6's link was changed from 6.5 to 6.6. The fix was simple but this prompted me to add a few features to my local yumrepo server & also create a script to automate creating a yumrepo server. I reorganized the folder structure so that I can have many yumrepos with different versions (but isolated from each other), giving me greater flexibility.

This series will show how to set up a local yumrepo server for CentOS 6.x using scripts, with minimal manual work. I am dealing with only x86_64 version in my tutorial, but you can easily adjust it to add i386 version also.

Terms

Some terms to know. I just came up with these for my own use.

  1. yumrepo: Usually known as Yum Repository. It's a place that contains rpms. A yumrepo can be accessed via http or ftp. I use http.
  2. Yumserver: It's a CentOS server that hosts rpms for yumclients to download when yum command is issued on the yumclient.
  3. Yumclient: Any CentOS server that downloads rpms from a yumrepo is a yumclient. Even a yumserver itself is a yumclient as it downloads rpms from a yumrepo.

Video demo

One minute video demo to show how easily you can create a yumrepo from scratch using my scripts. Obviously the whole process takes days to complete due to 10GB of data to download from a CentOS mirror server. By using my 2 scripts, the actual time you need to spend typing in front of your screen will be less than a few minutes. Watch in 720p if possible.

Create 2 yumrepos

Two separate yumrepos will be created. If you are familiar with using a local yumrepo already, you can skip to part 3 where you will create yumrepo 6.6.

  1. In part 2 , I will set up yumrepo 6.6basic. This yumrepo will only contain RPMs from the CentOS 6.6 install media. This yumrepo really won't be used in production. If you are new to setting up a local yumrepo, I strongly recommend that you go through part 2 before part 3.
  2. In part 3 , I will set up yumrepo 6.6. This yumrepo will contain all latest RPMs from CentOS 6.6, from both install media and updates that were released after the initial release of CentOS 6.6. It's recommended that you set your production CentOS servers to use this yumrepo. I will also discuss how to keep your new yumrepo 6.6 synched with latest RPMs.
  3. In part 4 , I will discuss options for configuring your fleet of CentOS to use the new yumrepo.

You can skip part 2 and just complete part 3 and you will have a fully functioning yumrepo server. Both part 2 and 3 are self-contained. Both or just one can be set up without affecting the other yumrepo. And yumclients can access each yumrepo without any interference. By modifying the procedure and scripts a bit, you can potentially have many different yumrepos for different versions/conditions. The only limitation would be HD space on the Yum server.

Comparing yumrepo "6.6basic" and "6.6"

  1. You skip part 2 and jump straight into part 3 to create yumrepo 6.6.
  2. Yumrepo 6.6basic and 6.6 can be installed on the same CentOS server and still function properly, completely independent of each other.
  3. Part 2 ( 6.6basic ) involved creating 1 script. When that script is executed, yumrepo 6.6basic will be created. The script will also generate and execute /root/bin/yum-createrepo-6.6basic.sh automatically.
  4. Part 3 ( 6.6 ) will require creating 2 separate scripts. When the first script is executed (to be executed only once), yumrepo 6.6 will be created. And it will also generate and execute /root/bin/yum-createrepo-6.6.sh. When the second script is executed, it will generate and execute /root/bin/yum-createrepo-post-rsync-6.6.sh.

Other yumrepos you can create

After creating 2 yumrepos, you will know how to create new yumrepos such as these.

  1. Yumrepo 6.5: yumrepo for CentOS 6.5. By setting a CentOS 6.5 server to use this yumrepo, you will prevent it from updating to CentOS 6.6 automatically when 'yum update' is issued. You should use latest version of CentOS (6.6 as of March, 2015) for production servers. But if you need CentOS to stay at 6.5 (with all updates released for 6.5) for dev/qa reasons, you can use this yumrepo 6.5.
  2. Yumrepo 6.7: CentOS 6.7 has not been released yet but when it is, you can create yumrepo 6.7. When you are ready to upgrade CentOS servers to 6.7, you can modify /etc/yum.repos.d/ on those servers to use yumrepo 6.7 and run yum update on those servers. Then all your CentOS servers will be upgraded to v6.7. Best thing about using your local yumrepo server is you can control precisely when your CentOS servers upgrade to v6.7.

KVM Server recommended

Before proceeding, I strongly recommend setting up a CentOS KVM server, which allows you to run virtual, separate instances of CentOS on 1 physical server. You really should not dedicate an entire PC/server box to 1 instance of CentOS. While going through this tutorial, you will need to install/work with multiple instances of clean CentOS. With KVM, setting up new CentOS instance is much easier. Thus, I highly recommend setting up KVM (or even Vmware) first.

By the way, after I am done with yumrepo blog series, I will post a blog on how to use KVM, local yumrepo server, Kickstart, and SaltStack to set up a very automated way to provision new instances of CentOS. Much like what you can do with Linode or DigitalOcean who allow you to provision full CentOS in minutes, but my blog will show how to set it up all on your own server in your home/office.

On to part 2, creating yumrepo 6.6basic.