Internal mirror using apt-cacher


apt-cacher

I have two computers at home, my PC and my lenovo S10e netbook, both on Debian.  What I’ve installed in one computer it’s likely to be installed in the other one (for instance, OpenOffice.org or Gimp), so every time I upgrade my computers I have to download the same packages twice. I wondered if there was a way to download all packages in one computer and use it as an internal repository….and the answers is yes, by using a cached repository like apt-cacher.

Installing apt-cacher

On Debian (or any spin-off like Ubuntu) you can install apt-cacher typing:

aptitude install apt-cacher

Setting the server

Defining mirrors

In order to set apt-cacher up, you have to edit the /etc/apt-cacher/apt-cacher.conf file. There are several parameters you can change to modify apt-cacher‘s behavior, but the most important to learn is the path_map parameter. By using that parameter you will be defining your internal mirrors. For instance, let’s say you want to set up two mirrors, one for Debian’s (main, contrib and non-free) repositories, and the other one for Debian-Multimedia’s repository. Here’s how you can define them:

path_map = debian http://ftp.us.debian.org/debian/ ; multimedia http://www.debian-multimedia.org

Enabling the service

In order to enable the service at boot time and set the port where the service will be listening, you must edit file /etc/default/apt-cacher as follow:

# set to 1 to start the daemon at boot time
AUTOSTART=1

# extra settings to override the ones in apt-cacher.conf
EXTRAOPT=" daemon_port=3142 limit=30 "

Importing old packages

If you have already downloaded a quiet few packages and you want to use them, you can import them to apt-cacher. For example, in order to import your .deb files located in /var/cache/apt/archives/, you can use the following command:

/usr/share/apt-cacher/apt-cacher-import.pl -r /var/cache/apt/archives/

The -r option stands for creating hard links or copying the archives (the -s option sometimes doesn’t work due to permission issues).

Restarting the service

Once you have finished to set up your server, you can restart  apt-cacher by using its service script:

/etc/init.d/apt-cacher restart

Setting the clients

Now you have to edit your clients’ repositories file, so they can connect to the new mirrors. For the mirrors you’ve created earlier, add the following lines into the /etc/apt/sources.list file:

deb http://192.168.1.100:3142/debian testing main contrib non-free
deb http://192.168.1.100:3142/multimedia testing main

In this example, 192.168.1.100 is  the server’s IP address. If you want to use a domain name, you can set a DNS server or just use the /etc/hosts file on each machine (it’s up to you).

Updating and upgrading clients

Now, you are ready to use your new mirrors. As usual, update the packages list and then proceed to upgrade your clients’ system:

aptitude update
aptitude safe-upgrade

Repeat client’s steps for every machine you want to connect to the cached server.

Reporting

apt-cacher comes with a report tool (see below picture) that it’s executed every day via crontab . If you wan to check how much  you have saved in bandwidth, you can go to http://localhost:3142/report or http://192.168.1.100:3142/report, or whatever you server’s IP address is. Since I installed apt-cacher, it have shared 366 MB out of  1104.7 MB downloaded…not bad at all :)

apt-cacher

Reference


,

  1. #1 by Luis Gallardo on 15/03/2010 - 11:26 am

    @Rino quizás sea que no estaba disponible el sitio, o que no pudo responder por el servicio…

  2. #2 by Luis Gallardo on 15/03/2010 - 11:16 am

    @Rino se ve bien lo que pones…

  3. #3 by Luis Gallardo on 15/03/2010 - 11:12 am

    @Rino eso puede ser que no está consiguiendo el paquete en los repositorios que definiste.

  4. #4 by Rino on 14/03/2010 - 2:40 pm

    Ahi lo arregle
    tuve que usar repositorios que no sean de ftp.

    deb http://www.us.debian.org/debian/ lenny main contrib non-free
    path_map = debian http://www.us.debian.org/debian/;
    Sun Mar 14 15:08:55 2010|3024|192.168.210.131|HIT|355936|libasound2_1.0.16-2_i386.deb
    Sun Mar 14 15:08:55 2010|3024|192.168.210.131|HIT|177256|libltdl3_1.5.26-4+lenny1_i386.deb
    Sun Mar 14 15:08:55 2010|3024|192.168.210.131|HIT|345726|libmpg123-0_1.4.3-4_i386.deb
    Sun Mar 14 15:08:55 2010|3024|192.168.210.131|HIT|129832|mpg123_1.4.3-4_i386.deb

    puede ser eso el error??

  5. #5 by Rino on 14/03/2010 - 1:56 pm

    path_map = debian http://ftp.us.debian.org/debian/ ; multimedia http://www.debian-multimedia.org

    debianhost:/etc/apt# cat sources.list
    deb http://192.168.210.132:3142/debian lenny main contrib non-free
    debianhost:/etc/apt#

    fue probado en dos maquinas virtuales.

  6. #6 by Rino on 14/03/2010 - 1:53 pm

    MIra el error quente..

    Sun Mar 14 14:17:21 2010|192.168.210.1|— /usr/sbin/apt-cacher: Usage error
    Sun Mar 14 14:17:23 2010|192.168.210.1|— /usr/sbin/apt-cacher: Usage error

    Sun Mar 14 14:22:02 2010|6625|192.168.210.131|MISS|92516|ftp.us.debian.org_debian_dists_lenny_contrib_binary-i386_Packages.gz
    Sun Mar 14 14:22:15 2010|6625|192.168.210.131|MISS|122132|ftp.us.debian.org_debian_dists_lenny_non-free_binary-i386_Packages.gz

    Slaudos

(will not be published)