Home > Ubuntu > Saving Bandwidth With Apt-Cacher : Revisited

Saving Bandwidth With Apt-Cacher : Revisited

Those of you that are long time readers may remember my previous article on Saving Bandwidth With Multiple Machines Using Apt-Cacher. With the next Ubuntu release coming down the pike in just a few weeks I wanted to revisit this article for those of you that will be upgrading via aptitude. If you have multiple machines you’ll really want to look into setting this up!

I’ve been testing and retesting different hardware running Ubuntu 7.10 alpha and now beta releases. Nothing is worse than installing two machines and downloading the same updates twice, one for each machine. Apt-Cacher steps in at this point and lets us just download the update once to then be shared by all. Let’s revisit the setup:

Installing Apt-Cacher

The first thing you’ll need to do is select a central machine that you’ll want to act as your apt-caching service. I use one of my old servers sitting in the closet, but this could be one of your desktops if you like. You should note that this machine will need to be on any time another networked machine wants to request an update. On this single machine we’ll install the apt-caching service:

sudo aptitude install apt-cacher

Configure Apt-Cacher

You’ll also want to set this service to auto start at boot time. To do this make the following change:

sudo vim /etc/default/apt-cacher

change AUTOSTART=0 to AUTOSTART=1

You’ll also want to updated the access restrictions to allow your local machines access to this service. By default only localhost (127.0.0.1) will be allowed.

sudo vim /etc/apt-cacher/apt-cacher.conf

change allowed_hosts=127.0.0.1 to allowed_hosts=192.168.0.0/24 (update to your range as appropriate)

Once you’ve made these changes you’ll need to restart the apt-cacher service on the central machine:

sudo /etc/init.d/apt-cacher restart

Configure the Clients

You can configure your client machines (the other machines on your network) to use this apt-caching system with a simple edit to the apt sources.list file. Make sure you know the IP address of the apt-caching server you configured above.

If your sources.list currently looks something like this:

deb http://archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ gutsy-security main restricted universe multiverse

prefix the address to include the caching-server IP address: (replace 192.168.0.3 with your local server IP)

deb http://192.168.0.3:3142/archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb http://192.168.0.3:3142/archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb http://192.168.0.3:3142/security.ubuntu.com/ubuntu/ gutsy-security main restricted universe multiverse

Once you’ve done this to the clients you should be able to fetch and install updates via the central machine and save bandwidth. Once a package has been fetched for one machine it will stay available centrally for each of the others therefore saving bandwidth and increasing update times by using LAN speeds vs WAN speeds.

If you’re interested in more information see my previous post on the topic or see the man page for apt-cacher (man apt-cacher).

If this article has been helpful, please consider linking to it.

Categories: Ubuntu Tags:

Related Posts

  1. Matt Mossholder
    October 3rd, 2007 at 10:09 | #1

    The alternate approach on your clients is to leave the urls in sources.list alone, and configure a proxy server in apt.conf that points to apt-cacher. It makes it a lot easier to turn it on and off, as well, as requiring less effort.

  2. October 3rd, 2007 at 10:16 | #2

    Mr Troll,

    When it comes to something as important as package management, I prefer to not have my computers automatically doing anything, especially selecting new repositories. Perhaps having that functionality automated would be nice, but it should never be enabled by default. The setup here is truly not that difficult and basically involves 1) installing the apt-cacher package, 2) turning it on, and 3) pointing the other boxes to it. That’s exactly how it should be.

    Now, if you want to make the argument that there should be a nice little gui for the process that shows you all the options and automatically scans for available cache servers on the network and provides them in a list that you can choose from, that is all well and good (as long as you are offering to write the gui yourself). But please don’t try to make the computer smarter than I am and do a bunch of dumb things because it is trying to “help” me. I work on networks for a living and get paid a whole bunch of money to fix those exact types of problems in other operating systems.

  3. Karl Bowden
    October 3rd, 2007 at 17:03 | #3

    Hey Christer,
    I would also recommend approx.
    It seems the approx and apt-cacher do almost exactly that same thing and setup of approx was very much the same except the domain is defined in the approx setup file instead of on the client sources.list.
    The only advantage I had with this is that when one of the mirrors I was using started timing out, I simply changed the mirror name in approx.conf, restarted approx and then all of the machines using it as it’s source were still functioning as normal.

    Karl

  4. Richard
    October 8th, 2007 at 11:42 | #4

    I really recommend not changing the sources.list in all the clients, but simply putting this into the relevant /etc/apt/apt.conf.d file – I used 90apt-proxy-local. See http://www.debuntu.org/how-to-set-up-a-repository-cache-with-apt-cacher-p2 for the line to put in this file, and some other good tips such as how to migrate packages already in the APT cache into the apt-cacher cache.

  5. Richard
    October 8th, 2007 at 11:44 | #5

    The key line to put in a file under /etc/apt/apt.conf.d is:

    Acquire::http::Proxy “http://cache-host:3142″;

  6. Thorne
    December 15th, 2007 at 17:25 | #6

    Well I need some info about this apt-cacher.
    I have dapper (lts) and feisty and guttsy. how can I set it up to use this “apt-cacher”. Do i i use different sub directory’s for each of have them all going in the same directory??
    I would very much like to use this program for my repository cache but just don’t know how to set it up to use it. can anyone please help…

  7. May 4th, 2008 at 19:10 | #7

    You may also want to try apt-cacher-ng.

    http://packages.debian.org/sid/apt-cacher-ng

    “It was redesigned from scratch and is written in C++ with main focus on maximizing throughput with low requirements on system resources.”

  8. Ivan
    October 27th, 2008 at 08:05 | #8

    Also, if you change sources.list, sudo apt-get update is required.

  9. January 18th, 2009 at 22:52 | #9

    You save my live sir. Thank you!

  10. January 22nd, 2010 at 06:41 | #10

    I’d like to thank both Christer for the article and Brian for his comments.

    I got apt-cacher-ng installed last night for our small network and its working perfectly saving us bandwidth and time.

    Good work guys!
    Mark Waters

  1. No trackbacks yet.