Can I easily make a host “mirror” that caches downloaded Debian packages?

We’ve got a Squid web cache set up that is used for caching package downloads, so that all the machines here don’t have to independently redownload everything. The installer prompts for a mirror and proxy. As long as every machine uses the exact same mirror (here, http.us.debian.org) and the proxy then it works.

That’s somewhat annoying, as it involves going to ‘enter information manually’ and typing it in each time (as the installer would do ftp.us.debian.org, which Squid doesn’t realize is identical).

The installer defaults to just mirror, is there a way to make that work? So I can be lazy and just hit enter a bunch?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

For having a local deb cache to server my Debian server farm, I actually prefer to use apt-cacher-ng (caching proxy server for software repositories)

It is a proxy specially APT/deb aware, quite customisable and can cache your deb files for quite a while (configurable).

You install it with:

apt-get install apt-cacher-ng

And by default it caches repositories/debs into /home/apt-cacher-ng. Under this directory, it creates a directory per repository used in your Debian/Ubuntu servers, then distros used, much similar to mirror structures. As an added bonus, is also much easier to fetch manually a deb from cache from here, than from a Squid server.

To use it in all your servers, add to the directory /etc/apt/apt.conf.d a file 02proxy with the contents:

Acquire::http { Proxy "http://your_proxy_APT_server:3142"; };

After you add that file, the Debian package manager will proxy all the configured repositories via the configured http APT proxy.

It also got an interesting statics page for consulting it´s activity.

You might also need to open 3142/TCP in your firewalls to allow the servers to talk with your new proxy APT server.

The advantage of such setup is that besides downloading only one deb copy for a bucketload of servers, and saving bandwidth and the public repositories usage is that allows you to update internal servers that do not need to have Internet access (example: DHCP servers).

As documented in Appendix B of the Official Install Guide, you can have your DHCP server give out a preseed file, by adding something like this to it’s config:

if substring (option vendor-class-identifier, 0, 3) = "d-i" {
    filename "http://host/preseed.cfg";
}

Then using these preseed options, you can configure the mirror and proxy automatically:

d-i mirror/protocol string http
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string http://your_proxy_APT_server:3128/

See also: How to set up Apt caching server on Ubuntu or Debian

Method 2

edit: The preseeding approach I edited in to Rui F Ribeiro’s answer works with Squid—or any other proxy—as well, and (as long as you’re using DHCP) is likely a better approach.


First, mirror will be completed with the system domain name, so add a DNS entry for mirror.yourdomain.com. Point that to a server running Apache; in this example, the same server also runs Squid.

Make sure Apache has both mod_proxy and mod_proxy_http enabled (e.g., a2enmod proxy; a2enmod proxy_http on Debian). Then add a new virtual host:

<VirtualHost *:80>
    ServerName mirror.yourdomain.com
    ServerAlias mirror

    ProxyPass /debian http://http.us.debian.org/debian
    ProxyRemote http http://localhost:3128/
    ProxyVia off
</VirtualHost>

After restarting Apache, package downloads from the Debian mirror “mirror” should go through the cache.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x