How to Configure Local Apt-Cacher-Server for Intranet -- Raja Arulappagari

Server Installation:

1. Install apt-cacher and apache2 webserver

#apt-get install apt-cacher apache2

2.Enable apt-cacher

Edit /etc/default/apt-cacher and change autostart to 1. (This will automatically start
cache server).

#vi /etc/default/apt-cacher


3.Restart the apache server

#/etc/init.d/apache2 restart

4.Restart the apt-cacher server

#/etc/init.d/apt-cacher restart

Now test your apt-cacher server.Go to remote machine in your your
browser type the hostname or IP address of your apt-cacher

#firefox http:///apt-cacher  [ hostname / ip ]

sometimes it won't work. Then try

#firefox http://hostname/ip :3142";

save and quit


Create a small script.


. /lib/lsb/init-functions
log_daemon_msg "Configuring APT cache proxy" "(based on SERVER_NAME_HERE's
ping -c 1 SERVER_NAME_HERE &> /dev/null
if [ $? = "0" ]; then
echo "Acquire::http::Proxy \"http://SERVER_NAME_HERE:3142\";" > /etc/apt/
rm /etc/apt/apt.conf.d/01SERVER_NAME_HEREproxy &> /dev/null
log_end_msg 0


(Note: Replace SERVER_NAME_HERE with the ipaddress of apt-cacher server).
save and quit
#chmod +x /root/check-apt-cacher
#crontab -e
*/1 * * * * /bin/bash /root/check-apt-cacher
save and quit
This script will run each minute (*/1) you can change it as you see fit.
You're done.
How It Works?

In each and every client machine in our network, we are going to mention the apt-
cacher server as a proxy server in the /etc/apt/apt.conf.d/ directory. So in our network,
If anyone Downloads packages using apt-get command. First, it checks in the cache
folder of apt-cacher server i.e.., /var/cache/apt-cacher/packages. If it doesn't find any
packages, it downloads from the internet and keeps in its cache folder and as well as
installs on the client machines(regardless of what version of ubuntu they are using). So
that if any other people tries to install the same package,they can directly install it from
the cache instead of hitting internet all the time,which saves bandwidth.
(Note : I have installed apt-cacher server on ubuntu 9.04 and i tried to access from
client side which is of ubuntu 9.04 and ubuntu 10.04. i installed few packages on the
client side, which client and as well as server doesn't have. The new package is fetched
form the internet and is kept in the apt-cacher cache directory.)

No comments: