Saturday, August 8, 2009

Apt-mirror vs. apt-cacher-ng

After playing around with apt-mirror and some more research I decided to replace it with apt-cacher-ng.

Problems with apt-mirror:
  • It uses up a lot of space, most of it for packages we will never use
  • It needs just as much space for every additional architecture or release of Ubuntu/Debian
  • Because we don't use majority of the packages apt-mirror downloads, more bandwidth is wasted than necessary
  • It is necessary to modify apt's sources file to force clients to use apt-mirror, this becomes more difficult when some clients use different repositories
  • Requires installation of a separate web server
Alternative solution is to use a special caching proxy that will fetch packages that we actually use and cache them for future requests.

Benefits of apt-cacher-ng:
  • It uses fraction of the space, especially since cache is automatically cleansed of old packages that are no longer requested
  • It downloads each package only once, thus reducing bandwidth consumption
  • It reduces download time for all but the first request (Gigabit LAN speeds, baby)
  • Makes it easier to configure clients: instead of changing repository URLs we only change the address of the proxy
  • Single package install, no additional web server needed
  • Minimal server side configuration, in fact almost zero configuration in our case
Implementation steps:
  1. Install apt-cacher-ng
  2. Configure apt-cacher-ng to use Squid proxy
  3. Configure VMs to use apt-cacher-ng instead of Squid
Step one, install the package:
apt-get install apt-cacher-ng
Step two, add Squid proxy address to /etc/apt-cacher-ng/acng.conf. There is already a sample line there, just uncomment and make it look like so:
proxy: http://my-proxy.lan:3128
Step three, edit /etc/apt/apt.conf on every VM to use our apt-cacher-ng server, like so:
Acquire::http::Proxy "http://my-apt-cacher.lan:3142/";
Since this line is identical for all VMs it's a lot easier to automate/script.