My ongoing experiences with Ubuntu, and later Mythbuntu, as a media center with MythTV. I'm also using the system for a virtual machine server, a mediawiki server and a general all around home infrastructure base.

Thursday, October 30, 2008

Installing apt-cacher

In preparation for upgrading to 8.10 I decided to install a apt-cacher on my home network. Basically I followed the directions at the link in the prior sentence with some tweaks as described below.

First, install:
# apt-get install apt-cacher

Then configure the deamon to always be on by editing /etc/default/apt-cacher and changing AUTOSTART=0 to AUTOSTART=1:
vi /etc/default/apt-cacher

Then I edited /etc/apt-cacher/apt-cacher.conf to restrict access to my local network. I also added the path_map directive, though I'm pretty sure I'm not using it right now.
# cd /etc/apt-cacher
# cp apt-cacher.conf apt-cacher.conf.orig
# diff apt-cacher.conf.orig apt-cacher.conf
< allowed_hosts=* --- > allowed_hosts=,
> path_map = debuntu ; ubuntu; ubuntu-updates ; ubuntu-security

Ok, first addition to the directions here. Later when the anacron job /etc/cron.daily/apt-cacher ran, I got the following errors:
Use of uninitialized value in concatenation (.) or string at /usr/share/apt-cacher// line 169, <$listpipe> line 244.
Use of uninitialized value in concatenation (.) or string at /usr/share/apt-cacher// line 169, <$listpipe> line 245.

I found this bug report describing the error. Following the report, I edited /usr/share/apt-cacher/ as described in the bug report.

Ok, now you are ready to fire up apt-cacher. The missing log messages happen the first time and then went away.
# /etc/init.d/apt-cacher restart
Restarting Apt-Cacher: apt-cacherWarning: /var/log/apt-cacher/access.log missing. Creating.
Warning: /var/log/apt-cacher/error.log missing. Creating.

At this point you should be able to point your web broser at http://cache-host:3142/ (replace "cache-host" with the actual IP or hostname of your host) and see the apt-cacher status page. You can also visit http://cache-host:3142/report/ to get a report of how well your cacher is doing, though it won't have any interesting content until it's been running for a day.

Then I imported existing package from /var/cache/apt/archives/ to apt-cacher repository:
# /usr/share/apt-cacher/ /var/cache/apt/archives

Ok, now to configure the client systems, including the system on which apt-cacher is running, I followed the advice from EWB's comment and created /etc/apt/apt.conf.d/90local-proxy on each system (again, replace cache-host with your actual IP address or hostname):

# vi /etc/apt/apt.conf.d/90local-proxy
# cat /etc/apt/apt.conf.d/90local-proxy
Acquire::http::Proxy "http://cache-host:3142";

Now you can do a apt-get update. Expect this to take a while the first time you run it.

# apt-get update

That's it. Just sit back and enjoy the caching.

Update: After upgrading 5 systems (1 server, 3 VMs and my laptop) to 8.10 using the cacher, here the stats from the report for the day showed it saved me 48% of my apt-get traffic (956MB out of 1980MB).
Post a Comment