...

Monday, May 24, 2010

Misc 27

At times when your network undergoes a major software upgrade, it is actually unfeasible to connect computers individually to the repositories. This can be both time and bandwidth consuming and causes scalability issues for the network.
Apt-proxy turns your computer into a caching server, and all clients in turn connect to the computer instead of the repository. In this case, each package only needs to be downloaded once and stored. Subsequent requests for the cached package would be retrieved from the caching server.

In this case, we'll run a simple topology to demonstrate how apt-proxy works. Suppose we have a topology that looks like this:


In this topology, we have the apt-proxy, and two clients in the same subnet. They don't necessarily need to be. All traffic is to go through the HTTP proxy.

We'll first set up the caching server. The package we need to install is:
apt-get install apt-proxy

At this point, apt-proxy is functional if your client uses the US server with no HTTP proxy required. However, since our topology requires a HTTP proxy, we'll have to do some setting up.

The first thing we need to modify is the configuration file. The file is located at /etc/apt-proxy/apt-proxy-v2.conf:
nano /etc/apt-proxy/apt-proxy-v2.conf

There are a few parameters we need to modify. Notice that there is an "address" parameter. If you do not specify it, the server will listen to all available interfaces. By default, it will listen to port 9999, but you can change it there as well. The first parameter we'll modify is the http_proxy parameter. Since our http_proxy is at 192.168.1.2:80, we'll modify it as shown:
http_proxy = 192.168.1.2:80

The proxy can also be a DNS name instead of an IP address.

Scroll down and you'll find a section for backends. This is where you'll add your alternate mirrors. For this purpose, I'll leave it with the defaults. If you wish to add more repositories, you can do so like this:
backends =
http://mirror.nus.edu.sg/Debian


Now it's time to set up the client. To do this, we'll modify the sources.list file:
nano /etc/apt/sources.list

Modify it to reflect the IP address of the apt-proxy like this:
deb http://192.168.2.2:9999/debian lenny contrib main non-free

Do an update and it should be working like as if it's directly connected to the internet.

Steering a little off topic. Suppose that you wish to have something start up automatically for all users. The file you would want to edit is the /etc/environment file. A good thing to add in there is a HTTP proxy like this:
export http_proxy=http://proxy.tp.edu.sg:80/
export no_proxy=localhost,127.0.0.0/8,152.226.152.0/21


An alternate file would be the .bashrc under your home directory. However, it only affects the particular user so it's not very useful for exporting proxy settings.

No comments :

Post a Comment

<