Ubuntu deb proxy and cache: squid-deb-proxy and apt-cacher-ng

Written by
Date: 2013-02-04 09:44:00 00:00


Ubuntu, Debian and all other Linux distributions use a lot of bandwidth by updating its packages. You can save both bandwidth and time by installing a proxy-cache that stores copies of downloaded packages and serves them locally to other computers when requested.

Actually any cache will do. The problem about using any cache system (like squid or polipo) is that them also cache other files and pages besides the Ubuntu deb packages. This makes easier for some package to be discarded from the cache and it may have to be downloaded again if you have a fast rotating cache, or if you do not have too much space on the cache.

The solution is to have a cache only for Ubuntu's deb files.

There are a lot of options, but I have found two that seems to be the easiest and most easier to install and maintain, at least for me.

squid-deb-proxy

Squid-deb-proxy is as its name suggest, based on Squid, with a pre-defined configuration file and acl list to serve one specific purpose, which is cache deb files.

This is the easiest solution, and easiest to maintain and install, it requires no configuration on the client side, and almost or no configuration on the server side.

Install on the server

sudo apt-get install squid-deb-proxy squid-dep-proxy-client

Install on clients

sudo apt-get install squid-deb-proxy-client

If you are only using official repositories, there is nothing else to do, while on the same network all clients will look for a cache copy of the needed files. If there is no one, the server will fetch one from ubuntu servers and serve it to the client while keeping a copy for the next requirement.

If you need to use some other repository beside officials, you will need to edit the file /etc/squid-deb-proxy/mirror-dstdomain.acl and add them there. Other than that there is not need for further changes.

One pitfall I can see, is that there is no way to pre-populate the cache with deb files you may already have in a disk or your own PC in /var/cache/apt/archives/. And this is bad if you are behind a mobile or satellite connection.

apt-cacher-ng

apt-cacher-ng is a specialized tool.

"Specialized for package files from Linux distributors, primarily for Debian (and Debian based) distributions but not limited to those."

Of course as a Debian derivative it works great with Ubuntu. The installation is only performed on the server, and the configuration on the client.

Install on the server

sudo apt-get install apt-cacher-ng

There is nothing else needed, and it should work from this point.

Configure de client

This configuration, should also be done on the server, so it can use the cache too.

Edit the file /etc/apt/apt.conf and add this lines::

Acquire::http { Proxy "http://192.168.122.162:3142"; };

Replace 192.168.122.162 for the IP of your server.

Import the deb files you already have

To import the deb files to the cache, just copy all deb files you already have to /var/cache/apt-cacher-ng/_import, if it does not exists, you have to create it. Then go to: http://192.168.122.162:3142/acng-report.html (Change the IP for the IP of your server, look for the Start Import button, and click on it. Wait for some minutes and when it finished the job, you can delete the _import folder and all its contents.

Conclusion

Using the right tools, there is no need to waste bandwidth, If you have more than two computers, this kind of solution worth the time of setting it up, specially with desktop computers. With laptops it is a good idea too, and run upgrades when you are in the server's network.