Posts Tagged ‘atp-cacher-ng’

An Apt Server using apt-cacher-ng

17, May 2009

I decided that due the increasing number of PC’s and laptops in the house all requiring the same package downloads from Ubuntu that downloading them once to a server and then serving them onto the various other machines was a better use of my broadband bandwidth. I therefore decided to install apt-cacher following this post with some changes, the main one being I used the Debian version of apt-cacher called apt-cacher-ng.

The PC I used for this is a laptop with a missing screen [don’t ask] with a standard install of Ubuntu.

First install apt-cacher-ng by copying & pasting the following into a terminal after the prompt;

sudo apt-get install apt-cacher-ng

and test that the service is running by typing this to http://your_server_name:3142/apt-cacher-ng into your web browser changing the your_server_name to the name of your server or it’s ip address. When I installed Ubuntu on my server I called the PC bob during the installation therefore I used http://bob:3142/apt-cacher-ng. You can also use http://[localhost]:3142/ the page that gets displayed is an error page with info. and links to various web pages.

If you want to change any of the settings in the apt-cacher config file then, copy & paste the following into your Terminal;

sudo gedit /etc/apt-cacher-ng/acng.conf

I changed the location of the Cache directory so that it was outside my o/s partition and within my home partition as the folder get quite large. If you do this then you need to change the permissions on the folder to add the apt-catcher-ng user group.

sudo chown -R apt-cacher-ng.apt-cacher-ng /Path/To/Your/New/apt-cache-archive

you can now update the repository source list on the server & all the client PC’s or add the redirection in /etc/apt/apt.conf.d/.

Redirection Method

adding a file called 02proxy to /etc/apt/apt.conf.d/ to redirect apt/synaptic requests via server to apt-cacher.
In a Terminal;

touch ~/02proxy

this creates a file called 02proxy in your home folder.

echo ‘Acquire::http { Proxy “http://bob:3142”; };’ >> ~/02proxy

change bob to your server name, this adds the line Acquire::http { Proxy “http://bob:3142”; };¬† to the file

sudo mv ~/02proxy /etc/apt/apt.conf.d/02proxy

this moves the file from your home folder to /etc/apt/apt.conf.d/

now go to “continue from here” below.

The source.list Method

Backup first In a terminal copy & paste;

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

to make a backup of the list in the same directory, then there are a couple of options to amend the sources.list file;

Option :1

sudo gedit /etc/apt/sources.list

when this opens you need to insert your_server_name:3142 in every line, i.e.

deb http://archive.ubuntu.com/ubuntu/ Jaunty main restricted

becomes

deb http://your_server_name:3142/archive.ubuntu.com/ubuntu/ Jaunty main restricted

which made mine look like this;

deb http://bob:3142/archive.ubuntu.com/ubuntu/ Jaunty main restricted

you can use the search and replace option in gedit to make this a faster process then save and close it.

Option :2

Another option is to open a Terminal and type;

sudo sed -i ‘s/http:\/\//http:\/\/bob:3142\//g’ /etc/apt/sources.list

this uses sed to search for the string http:// in each line of the sources.list file and replace it with http://bob:3142/, you just need to replace bob with the name of your server.

continue from here;

now restart the apt-cacher-ng

sudo /etc/init.d/apt-cacher-ng stop

sudo /etc/init.d/apt-cacher-ng start

if you get a permissions error here check the permissions on your new apt archive folder.

and update the source list with

sudo apt-get update

to update the package list.

if you get errors it’s worth rebooting the PC and trying again especially if you changed any details in the conf file.

Once the update has run you should see that it has placed several directories and files in the Cache directory at /var/cache/apt-cacher-ng or wherever you moved it too.

Now go to your client PC and after updating it’s source list run the apt-get update command to make sure that works ok.

Now we need to import any existing packages in the servers apt-get cache into the apt-cacher-ng cache, so copy and paste into a Terminal;

$ test -x /var/cache/apt-cacher-ng/_import || sudo mkdir -p -m 2755 /var/cache/apt-cacher-ng/_import

change the path if you have moved the cache ddirectory, this creates a new directory called _import within it.

Now in a Terminal;

$ cd /var/cache/apt/archives

import the old packages with:

sudo  cp *.* /var/cache/apt-cacher-ng/_import

Now open the apt-cacher-ng info. page at http://your_server-name:3142/acng-report.html

scroll down to the bottom of the page and hit the import button. After a while the import should finish and you should notice an increase in the space in the disk space that the cache directory takes.

You can now remove the _import directory with;

$ sudo rm -fr /var/cache/apt-cacher-ng/_import

and the old apt cache with;

$ sudo rm -fr /var/cache/apt/archives/*.deb

to save space.

Now download a different packages on each of your PC’s so that you can check each PC’s downloads are going into the apt-cacher-ng cache on the server. The only way I found to do this was to check the number of files in the cache at /var/cache/apt-cacher-ng using properties then add a package and re check to see if the count increased.

The apt-catcher-ng service produces a report at http://your_server_name:3142/acng-report.html i.e. mine is at http://bob:3142/acng-report.html.