apt-cacher is an excellent proxy server for caching .deb packages. It integrates into apt so that when a package is requested, apt-cacher checks to see if there is a cached copy. If there is, it sends the cached copy. If there isn’t, it downloads the package from the Internet, caches it, and sends it to the requesting server.
While it seems apt-cacher can cache .rpm files, I found pkg-cacher prior to learning about that. This article therefore explains pkg-cacher. Maybe in the future I will see if I can get apt-cacher working in a CentOS environment with working .rpm caching services.
From what I have read, pkg-cacher is a modified version of apt-cacher but includes support for RedHat and SuSE based distributions.
For some reason, pkg-cacher is not as popular as it should be. Because of that, it’s not in the CentOS base or epel repository. To work around this, you’ll need to download it from its homepage. At minimum, you will need two rpm files:
The first rpm contains the actual pkg-cacher program while the second contains the start-up script.
To install, first disable gpgcheck in /etc/yum.conf:
gpgcheck=0
Next, use yum to install the two files as well as any dependencies they need:
yum install pkg-cacher-0.9.6-1.noarch.rpm pkg-cacher-sa-0.9.6-1.noarch.rpm
pkg-cacher is relatively easy to configure.
The config file is located at /etc/pkg-cacher/pkg-cacher.conf. The only change I made was to the path_map directive:
path_map = centos ftp.telus.net/pub/centos
What does this do?
Given the server that pkg-cacher will run on has an IP address of 192.168.255.1, if I configure yum on my servers to use
baseurl=http://192.168.255.1:3142/centos/$releasever/os/$basearch/
pkg-cacher will treat that URL as:
baseurl=http://ftp.telus.net/pub/centos/$releasever/os/$basearch/
The config file gives several path_map examples for other distributions to work from.
You might have to edit the /usr/share/pkg-cacher/static_files.regexp file as well. This file controls what files pkg-cacher chooses to proxy. I found that I had to add \.discinfo to get pkg-cacher to work in a VirtualBox environment and in a Cobbler/Koan environment, I had to add .* to just proxy everything.
And that’s really it. Just start pkg-cacher by:
$ /etc/init.d/pkg-cacher start
And your servers should now be able to utilize it.
Rather than copying full DVDs to my Cobbler install server, I like to use network install versions of distributions. Using pkg-cacher along with netinstall-based distributions creates a hybrid environment where my install server stores only packages that are needed for my servers.
To utilize pkg-cacher in a kickstart file, just point the install url to the URL you configured for pkg-cacher:
url --url=http://192.168.255.1:3142/centos/5.5/os/x86_64/
I did run into one issue with using pkg-cacher and kickstart. After it downloaded the minstg2.img or stage2.img file, it would just hang. Oddly, if I restarted pkg-cacher after I knew the img file was successfully sent, the install continued on as normal and continued to utilize pkg-cacher correctly.
By pure luck, I figured out the necessary hack to the pkg-cacher source code to fix this problem. It’s a simple one line fix. My patch is available here.
When working in a Debian or Ubuntu environment, apt-cacher has become an invaluable tool for me. I was happy to find a project such as pkg-cacher that brings the benefits of apt-cacher to the RedHat world.