PDA

View Full Version : Apt-Cacher: Setting Up Your own Repository


castaway
12-07-2006, 03:04 PM
Apt-Cacher: Setting Up Your Own Debian Repository


If you find yourself performing numerous Debian installations, you can save a great deal of time spent downloading by using a local repository. In my situation, since Sarge will soon be obsolete, I need packages for my Sarge LTSP server. (I will continue to run Sarge since WordPerfect 8 does not run with Xorg.)

Apt-cacher serves as an intermediary in the installation process. If the requested deb package is cached locally, a copy is transferred to your computer. If not, the server downloads the package to its cache and transfers a copy to your computer. Apt-cacher requires apache and several other files, all of which are downloaded with apt-cacher. Samba and nfs are not required; neither is X-windows. You need only a minimal machine. Required disk space ranges from several hundred megabytes to several gigabytes, depending on the number of packages to be cached.

NOTE: These directions have been tested only with Sarge.

***Installing apt-cacher on your server***

If your apt-cacher server does not have a static IP address, assign it one in /etc/network/interfaces. (This How-To uses 192.168.2.150.)

Install apt-cacher. Apt-cacher requires no configuration.

apt-get install apt-cacher

Because apt-cacher runs in conjunction with apache, it is started along with apache every time your computer boots. When installation is complete, start apt-cacher simply by starting apache:

/etc/init.d/apache restart

Next, install a text-only web browser:

apt-get install elinks

Start elinks by entering "links" at the prompt. A "URL" box will be displayed into which you should enter the following:

http://127.0.0.1/apt-cacher

This is the local address of apt-cacher on your apt-cacher server (127.0.0.1). If your installation is successful, the browser's "screen" will display the setup details for apt-cacher on your computer.

***Preparing client computers to use apt-cacher***

The only modification necessary for your local computers is to reset their /etc/sources.list to use your apt-cacher server. Prepend each listed source in the list with your apt-cacher server's "full" IP address.

Original version:

deb http://mirrors.kernel.org/debian stable main contrib

deb http://ftp.us.debian.org/debian stable main contrib

Revised apt-cacher version:

deb http://192.168.2.150/apt-cacher/mirrors.kernel.org/debian stable main contrib

deb http://192.168.2.150/apt-cacher/ftp.us.debian.org/debian stable main contrib


Modify the remaining entries by adding "192.168.2.150/apt-cacher/" between the double slashes and the web-address of the mirror. Then update apt-get:

apt-get update

***Modifying apt-cacher.conf***

Modifications to /etc/apt-cacher/apt-cacher.conf are necessary only if you want to alter the way apt-cacher functions. (The file need not be restarted after it has been revised.) Edit the file with nano:

nano /etc/apt-cacher/apt-cacher.conf

Some of the parameters you may want to alter include:

cache_dir
The location on your hard disk used for storing cached packages and package lists. Mine is installed on a hard disk different than the apt-cacher server.

expire_hours
Number of hours before the debian repository is checked for a new version of the requested file.

***Notes***

1. Apt-cacher daily traffic report.
On the server, enter the following address into elinks to view the report:

http://127.0.0.1/apt-cacher/report.

If you need to regenerate a report first, run:

/usr/share/apt-cacher/apt-cacher-report.pl

2. Old package cleanup.
Your cache will accumulate old packages. Apt-cacher runs a cleanup script every 24 hours, finds old packages no longer referenced by package lists, and deletes them.

3. Manually adding deb packages to your server's cache.
Before you can add packages to the cache which were NOT downloaded by apt-cacher, the packages must be modified to the apt-cacher format by running apt-cacher-import.pl. To modify the packages already in /var/cache/apt/archives and automatically import them into the cache directory, run, as root:

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

Other packages you need can be downloaded from the internet into an import directory on the apt-cacher server. Then run the above script using the import directory as the source instead of the source listed in the example.

4. Cdebootstrap.
Whenever you use cdebootstrap, modify cdebootstrap to point to your local repository:

cdebootstrap sarge /mnt/buildroot/ http://192.168.2.150/apt-cacher/mirrors.kernel.org/debian

5. Using apt-cacher to setup a Sarge repository for your own network.

1) For your apt-cacher server install only the "base system" of Sarge. You can use the modified instlux installation method found elsewhere in this forum (http://www.linuxagora.com/vbforum/showthread.php?t=477), a Debian Sarge installation CD, or cdebootstrap.

2) Before progressing to the "Debian software selection" menu, exit the program, <Ctrl> + <Alt> + <F2>. In the new terminal modify /etc/apt/sources.list by prepending your apt-cacher server address to each line. Then do an apt-get update.

3) Return to the installation program, <Ctrl> + <Alt> + <F1>. Select NONE of the options in the "Debian software selection" menu. Proceed with the installation.

4) Once installation is complete, install apt-cacher using the above directions.

5) On a second computer repeat Notes 5.1 & 5.2 above. After returning to the installation program in Note 5.3, choose from the "Debian software selection" menu whatever options you want. Remember that your goal is to fill apt-cacher's cache with packages that you may need in the future. Then do an apt-get install of any other packages you want to add to the cache. (If you prefer to work at the server's console when adding additional packages, you can use the method described in Note 3.0 above.) When you are satisfied with your software selections, remove Sarge from the second computer.

***References***
http://www.debuntu.org/how-to-set-up-a-repository-cache-with-apt-cacher
http://www.debianuniverse.com/readonline/chapter/19