Friday, December 4, 2009

Installing Varnish 2.0.4-5 on Ubuntu Hardy 8.04 LTS

*UPDATE

New and improved approach
apt-get update
apt-get install subversion autotools-dev automake1.9 libtool autoconf libncurses-dev xsltproc quilt debhelper
cd /tmp
svn co http://varnish.projects.linpro.no/svn/tags/varnish-2.0.6
cd varnish-2.0.6/varnish-cache
dpkg-buildpackage
cd ..
dpkg -i libvarnish1_2.0.6-2_i386.deb
 dpkg -i varnish_2.0.6-2_i386.deb


Unforunately this isn't as easy as it's supposed to be. I probably tried each component in this install three times each before finding a suitable codebase that actually compile and behave as advertised. As an example - the nagios plugin in varnish-tools folder failed to recognize -l which is the only logical way to use it in my option. And 2.0.5 src from sourceforge failed to compile in my system. But besides that, when it's all good it's good! :D

My (successful) steps are as follows:

Basic install

Find a suitable repository from http://packages.ubuntu.com/lucid/varnish and add to sources.list
sudo nano /etc/apt/sources.list
I used this one:
deb http://no.archive.ubuntu.com/ubuntu lucid main universe
Then update aptitude and install varnish from the repository
sudo apt-get update
sudo apt-get install varnish
Edit configuration file, you probably want it on port 80
sudo nano /etc/default/varnish
Set up configuration for backend nodes, examples for common issues can be found at http://varnish.projects.linpro.no/wiki/VCLExamples
sudo nano /etc/varnish/default.vcl

I also wanted varnish to serve up static files, including flv files for streaming so I added this to default.vlc:
sub vcl_recv {
 if (req.url ~ "\.(png|gif|jpg|ico|jpeg)$") {
    unset req.http.cookie;
  }
 if (req.url ~ "\.(flv)$|\?") {
   unset req.http.cookie;
   # Switch to pipe mode. Control will eventually pass to vcl_pipe
   pipe;
 }
}


Restart varnish to make use of your new config
sudo /etc/init.d/varnish restart
I had problems with varnishstat giving the error message: Cannot open /usr/local/var/varnish/dns.mydomain.com/_.vsl: No such file or directory

This was probably because I tried installing from source at first without much success

To fix it I had to point init script to another daemon path
sudo nano /etc/init.d/varnish
locate DAEMON=/usr/sbin/varnishd and change to
DAEMON=/usr/local/sbin/varnishd
and restart varnish
sudo /etc/init.d/varnish restart

Varnish Nagios plugin
Checkout nagios check util from svn:
svn co http://varnish.projects.linpro.no/svn/tags/nagios-varnish-plugin-1.0
Get dependencies
sudo apt-get install automake autoconf libtool
Compile it
cd nagios-varnish-plugin-1.0/
./autogen.sh
./configure && make && make install
Use it
/usr/local/libexec/check_varnish -l -c 30 -w 50
OK: 79 Cache hit ratio

No comments:

Post a Comment