2

I have three Ubuntu systems and I wish to minimize download bandwidth by setting up a cache of downloaded packages. (With only three systems, it's not worth setting up a full mirror).

apt-cacher-ng sounded perfect for this, but it doesn't work as I expected after setting up a trial with 1 server and 1 client.

When I install software on the client, it works as expected - packages are downloaded to the server and stored in the server's cache.

But when I install software on the server, the packages are not cached.

This kind of ruins apt-cacher-ng's utility for me - with only two systems, I will end up downloading the software packages twice anyway (like for kernel updates, etc). I would like it to cache the packages downloaded to be installed on the server; for me, there is a huge overlap between these packages and what the clients will request.

Is there a way to get apt-cacher-ng to cache the packages which are downloaded to be installed on the server?

2
  • Have you tried performing, on the server, the client setup instructions too in addition to the server setup instructions?
    – Daniel T
    Feb 11 at 23:24
  • 1
    @DanielT I was able to get it to work by changing the proxy to 'localhost' and rebooting the machine. If you care to write your suggestion as an answer, I'll be happy to accept it with thanks. Feb 12 at 0:06

2 Answers 2

2

To get the server machine to go through the cache, it also needs to be set up as a caching (apt) client. When you follow the apt-cacher-ng instructions for the server machine, you need to perform the steps for setting it up as both a caching (apt-cacher-ng) server and a caching (apt) client. Your unexpected situation looks like this:

unexpected situation with server apt not cached

In the case of the server, set its Acquire::http::Proxy to http://localhost:3142 instead of how the client machines set the proxy to be the server's hostname. This works and is more reliable. After this, the situation is as expected:

all apt is now cached

The 4 concepts of server machine (machine that runs both apt and apt-cacher-ng), client machine (machine that runs just apt), caching server (apt-cacher-ng), and caching client (apt) should not be confused. It's simple on the client machines. But on the server machine, its own caching client (apt) is not modified by the installation of apt-cacher-ng. apt-cacher-ng is a separate thing that you run, and setting the proxy to localhost will not cause a loop. In fact, the proxy must be set so that the server machine's caching client (apt) goes through the caching server (apt-cacher-ng) (coincidentally running on the same machine) in order to work as expected.

2

Supplementary answer with some tips for anyone who wants to do this:

  • I used the instructions at https://www.atlantic.net/vps-hosting/how-to-set-up-apt-caching-server-using-apt-cacher-ng-on-ubuntu/ (I found them more concise and focused than the official ones).
  • Make sure the file you add to /etc/apt/apt.conf.d to set up the proxy is world-readable or you will have to use sudo any time you do an apt policy.
  • If you want the cache in a non-default location, the owner and group must be apt-cacher-ng.
  • If you use a firewall on your server, you must open port 3142 to the appropriate client machines.
  • The caching process does not seem to interfere or interact in any way with the separate Debian 12 mirror I have set up on the same machine using apt-mirror, but I still have some testing to do on this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .