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
40c40
< allowed_hosts=* --- > allowed_hosts=192.168.1.0/24, 127.0.1.1
141a142,143
> path_map = debuntu repository.debuntu.org ; ubuntu archive.ubuntu.com/ubuntu; ubuntu-updates archive.ubuntu.com/ubuntu ; ubuntu-security security.ubuntu.com/ubuntu
>

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//apt-cacher-lib.pl line 169, <$listpipe> line 244.
Use of uninitialized value in concatenation (.) or string at /usr/share/apt-cacher//apt-cacher-lib.pl line 169, <$listpipe> line 245.

I found this bug report describing the error. Following the report, I edited /usr/share/apt-cacher/apt-cacher-lib.pl 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/apt-cacher-import.pl /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).

2 comments:

Unknown said...

Hie Von. I installed apt-cacher with no problems but cant update my clients. With their sources.list pointing to my machine (http://192.168.1.1:3142/ftp.x.x/ubuntu xx), i keep getting a resolution error on my clients for 'ftp.x.x'. How do i work around that?

Von Welch said...

DriftShin - not sure as I haven't encountered that problem. From your cache machine can you ping ftp.x.x? If not, you've got DNS issues you need to sort out. If so, it's some subtlety of apt-cacher beyond my comprehension. You might try using the local-proxy approach that worked for me.