Build your own Yum repository

By: Ian Winter

Tags:

  • yum
  • packagemanagement

One of the challenges we’ve had over the years is installing packages on RHEL and CentOS that either go away or are removed from major repos (EPEL/REMI/IUS), or, for things where we want to tie to a specific version of a package and maintain easy upgrade ability.

There are many ways to skin this cat, but, this is the way we chose. No cats were harmed in the making of this repository.

Create

First off, you’ll need to create some directories for your repo and packages to live in. You’ll need to do this for each version and architecture you’re going to support. In this case it’s RHEL/CentOS only and versions 5 and 6.

$ mkdir -p /path/to/yum/reponame/{5,6}/{i386,x86_64}

If you had multiple architectures & OS’ you might have:

/path/to/yum/reponame/CentOS/{5,6}/{i386,x86_64}
/path/to/yum/reponame/Fedora/{SRPMS,i386,x86_64}

Directories are up to you really depending on what you want to store.

You’ll also need the createrepo package, and repoview if you want an HTML setup as well:

yum install createrepo repoview

We’ve got a script that’s specific to our install and as I said assumes only one architecture, but, you can tweak as you need. The advantage of the script in this format is you can run it from wherever, say you have a common shared bin directory for instance.

$ cat ./build
#!/bin/bash

if (( EUID != 0 )); then
	echo "You must be root to run this command"
	exit 1
fi

[[ -n "$1" ]] && YUMREPO="/path/to/yum/$1" || YUMREPO=$( find /path/to/yum -mindepth 1 -maxdepth 1 -type d )

for REPO in $YUMREPO; do
	REPONAME=$( basename $REPO )
	for RELEASEARCH in $( find $REPO/[0-9]* -mindepth 1 -maxdepth 1 -type d 2> /dev/null ); do
		RELEASEVER=$( basename `dirname $RELEASEARCH` )
		BASEARCH=$( basename $RELEASEARCH )
		echo "Building $REPONAME RHEL $RELEASEVER ($BASEARCH): $RELEASEARCH"
		cd $RELEASEARCH
		createrepo -d .
		repoview -f -t "$REPONAME yum repo: RHEL $RELEASEVER $BASEARCH" .
		echo
	done
done

Once you’ve run it, you’ll have your repo.

Add packages & update

Now it’s built, you can add packages. Put simply, chuck an RPM in the right folder and rebuild.

Use it

Once you’ve create the repository it’s easy to then go ahead an grab a package from it.

On each server you want it to be available on, create a new repo file. We use puppet to ensure this exists where it needs to. Note that this example is only for RHEL/CentOS 6.

$ more /etc/yum.repos.d/reponame.repo
[reponame]
name=RepoName
gpgcheck=0
baseurl=http://yum.domain.com/6/$basearch/
enabled=1

Once you’ve added that, update Yum:

$ yum clean all

Then, go ahead and search for your package. We’ll use ImageMagick as an example:

$ yum --disablerepo=* --enablerepo=reponame search package

What we’re doing in the above is ensuring only our repo responds. After this point you can install or do whatever you need to.


About the Author

Ian Winter

Ian Winter is Head of Technical Operations for Venntro. He manages a team of four engineers who provide 24/7/365 support and are responsible for over 120 physical, virtual, storage and network devices.