If you have more than one PC using Debian or Ubuntu, you know that upgrading them makes most of the time download the same files more than once, and that is not good for your bandwidth.
I usually forward my requests to my Squid (in my office) and to my Personal proxy Polipo at home, it works, but apt-cacher may be a better approach as the way it decides if a file stays or is erased from the cache is more appropriate for .deb package than in Squid or Polipo, as they are optimized for web surfing.
Well, after that introduction, lets go to the interesting part of the post. Installing
To install it just run:
sudo aptitude install apt-cacher
The main configuration file is located at:
And you should check these parameters, which at least for me are the most important ones.
# cache_dir is used to set the location of the local cache. This can # become quite large, so make sure it is somewhere with plenty of space. cache_dir=/var/cache/apt-cacher # worried about unauthorised machines fetching packages through it, you can # specify a list of IPv4 addresses which are allowed to use it and another # list of IPv4 addresses which aren't. # Localhost (127.0.0.1) is always allowed. Other addresses must be matched # by allowed_hosts and not by denied_hosts to be permitted to use the cache. # Setting allowed_hosts to "*" means "allow all". # Otherwise the format is a comma-separated list containing addresses, # optionally with masks (like 10.0.0.0/22), or ranges of addresses (two # addresses separated by a hyphen, no masks, like '192.168.0.3-192.168.0.56'). allowed_hosts=10.1.1.0/24 denied_hosts= # Apt-cacher can generate usage reports every 24 hours if you set this # directive to 1. You can view the reports in a web browser by pointing # to your cache machine with '/apt-cacher/report' on the end, like this: # http://yourcache.example.com/apt-cacher/report # Generating reports is very fast even with many thousands of logfile # lines, so you can safely turn this on without creating much # additional system load. generate_reports=1 # Apt-cacher can clean up its cache directory every 24 hours if you set # this directive to 1. Cleaning the cache can take some time to run # (generally in the order of a few minutes) and removes all package # files that are not mentioned in any existing 'Packages' lists. This # has the effect of deleting packages that have been superseded by an # updated 'Packages' list. clean_cache=1 # apt-cacher can use different methods to decide whether package lists need to # be updated, # A) looking at the age of the cached files # B) getting HTTP header from server and comparing that with cached data. This # method is more reliable and avoids desynchronisation of data and index files # but needs to transfer few bytes from the server every time somebody requests # the files ("apt-get update") # Set the following value to the maximum age (in hours) for method A or to 0 # for method B expire_hours=0
Take care with cache_dir and be sure you have enough space in that partition to save all the data, which could be a lot of Mbytes!
Be sure that you have correctly configure the allowed_hosts and the denied_hosts in order to no compromise your server’s security, it is always advisable to install a good Linux Firewall
It is a good idea to have the generate_reports variable to 1, so you can access the reports at:http://yourcache.example.com/apt-cacher/report.
To have your cache automatically cleaned you need to enable the clean_cache variable, and also decide which method of cleaning is the best, the documentation recommends to use, method B (read above), so let expire_hours variable to 0
Start the server
To enable the server edit the file: /etc/default/apt-cacher and change AUTOSTART from 0 to 1, it may look like this:
# apt-cacher startup configuration file # IMPORTANT: check the apt-cacher.conf file before using apt-cacher as daemon. # 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 "
sudo /etc/init.d/apt-cacher restart
To check that everything is fine, open your favorite browser and go to:
Configure your computers to use the Cache
Now that you have your proxy running it is time to use it:
sudo vim /etc/apt/apt.conf
Put this info inside:
Be sure to change 127.0.0.1 to your server’s IP.
Another way to do it is:
Create a file 01proxy in /etc/apt/apt.conf.d/
sudo vim /etc/apt/apt.conf.d/01proxy
and copy the same above line about Acquiere…. inside.