Setting up Varnish 2.0.6 on Debian Lenny

Due to the strict rules of Debian many of the packages in stable releases are very old. In some cases though we want to run the latest version of a program, mainly due to new features and increased speed. The latest version of Varnish under Debian Lenny’s repositories is 1.1.2 (apt-cache show varnish), but in most cases we’d want to run the latest, especially with rapidly developed programs like Varnish. Varnish 2.0.6 is alos available in the Debian repository for SID/Squeeze or via backports.

apt-get install build-essential

Now we got most of the essential stuff for building the packages under Debian Lenny.

cd /root
wget http://sourceforge.net/projects/varnish/files/varnish/2.0.6/varnish-2.0.6.tar.gz/download
tar -zxvf varnish-2.0.6.tar.gz
cd varnish-2.0.6/

Now we have fetched the (as of now) latest stable version of Varnish from the developers them selves. Moving on we configure it and install it.

./configure --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var/lib --mandir=/usr/share/man
make
make install

This tells the compiler where to put stuff and then installs it. We’ve chosen most of the common places on Debian Lenny. This may vary on different operating systems. If you get any errors read them and install whatever it is missing. This should not be necessary if you remembered the first step.

 ldconfig

This tells Debian to update the location of the libs. This is vital to get Varnish to work on Debian Linux. Failing to do this step will result in a “file not found” when trying to start Varnish. (2)

cp redhat/varnish.sysconfig /etc/default/varnish

This is the main varnish configuration file. This has nothing to do with how Varnish handles request but how the daemon is run. If you are unsure how to configure this just run with “Alternative 2″.

DAEMON_OPTS="-a <out-side IP>:80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -u varnish -g varnish \
             -s file,/var/lib/varnish/varnish_storage.bin,512M"

This is a pretty basic setup that listens to port 80. The control daemon runs on localhost:6082. This you can telnet into and get various stats, load/unload configuration files when Varnish is running. Very useful tool when tuning your Varnish configuration. Also, this setup uses a 512MB cache-file, this might be too high or to low for your site, depending on how much memory you have avaliable and how much content needs/can be cached.

nano /etc/varnish/default.vcl

This is where the main configuration is done. You should set it up with atleast one backend server. Personally i run Apache2 with appropriate tools as backends, but you may run any web server of your choice. Try running your backend servers locally bound to port 80, this way you can trick them into not rewriting url when Varnish forwards the requests to them. If you do this remember to bind Varnish to your out-side IP-address, or else you will not be able to bind two applications to the same port.

/usr/local/sbin/varnishd -f /etc/varnish/default.vcl

This will start Varnish, telling it to use the configuration file located in /etc/varnish/. If you did all your steps right you should be seeing something like this in your HTTP headers. You should make a startup-script for this if you are running it on a production server. (1)

X-Varnish: 1861896702
Age: 0
Via: 1.1 varnish

Now we’ve got a fully functioning setup of Varnish. Before you run this on a production site you may want to consult with the developers of Varnish to tune the installation to your needs. You should also make varnish run under it’s own user and group. Varnish does this by default but you have to actually add the user first.

adduser varnish

This should add the user. You may want to edit /etc/passwd and set it up with no shell access. Do this by editing “/bin/bash” to “/bin/false”. You may also want to set a strong password all though this is not essential as the user has no shell access, and this should, to my knowledge, remove the need for a password.

Resources:
(1) http://www.all2e.com/Ressourcen/Artikel-und-Fallstudien/Varnish-installation-and-setup-on-ez-publish-based-systems
(2) http://varnish-cache.org/changeset/4420
(3) http://varnish-cache.org/
(4) http://kristianlyng.wordpress.com/

One Comment

  1. CAMERON says:

    Medicamentspot.com International Legal RX Medications. Special Internet Prices (up to 40% off average US price). NO PRIOR PRESCRIPTION REQUIRED!…

    Combivir@buy.online” rel=”nofollow”>.…

Leave a Reply