Web tech note–Why and how I downgraded from Varnish 3 to 2

Sometimes it seems to make sense to get the latest version of software you are using, especially if the upgrade is free! In the case of Varnish caching reverse proxy, it is not a good idea, unless you are running a complex installtion which requires the newer version’s features. This site is being served but not cached by Varnish. However, several Drupal sites on the same server are being cached by Varnish. For Varnish 2 there are ready-made configuration files (in Varnish’s native VCL configuration language) such as that from Pressflow. For Varnish 3 you are on your own.

The VCL syntax changed a bit from Varnish 2.0 to 2.1 but getting the config file working is not too hard. Getting Varnish 3 working with Drupal is a royal pain, and you are pretty much going to have take responsibility for writing your own VCL file. Once it is working, for a simple installation, it is if anything less efficient than Varnish 2. This is all discussed on the Drupal forum. With most of these config files, even when you get them to work so that caching (albeit some say caching less well than Varnish 2), logging in to your Drupal (or WordPress) site can break.

Upgrading is easy. Install the rpm and hit yum update varnish or yum install varnish. Yum might even find it without installing the rpm. Downgrading is more tricky.

First I did a yum remove varnish. However, once version 3 is on your server, yum install varnish will reinstall it. On a Centos server I had to go to /etc/yum-repos.d and delete the Varnish repository. Then reinstall the earlier versions of the varnish libraries. The single noarch bundle (find packages here) did not work for me on my 64 bit Centos el5 server.

If you are doing a fresh install, note that installation is tricker on 64 bit OS because it is all too easy to get the wrong versions of the various libraries required by Varnish. Be careful about to get the correct ones.

Then I had to install the old rpms:
rpm –nosignature -i http://repo.varnish-cache.org/redhat/varnish-2.1/el5/x86_64/varnish-libs-devel-2.1.5-1.x86_64.rpm
rpm –nosignature -i http://repo.varnish-cache.org/redhat/varnish-2.1/el5/x86_64/varnish-libs-2.1.5-1.x86_64.rpm
rpm –nosignature -i http://repo.varnish-cache.org/redhat/varnish-2.1/el5/x86_64/varnish-2.1.5-1.x86_64.rpm
(Go to the same URL for the relevant debug and docs libraries.)

Now yum install varnish. Find varnishd (for me in /usr/sbin) and do varnishd -V to check you have version 2, not version 3! The config file (for me at /etc/sysconfig) is overwritten by every upgrade or downgrade, so you need to edit it for the location of your VCL file, and to put Varnish on port 80. Should be good to go!

If you have not used Varnish before, once you have proved it will start from command line, of course you are likely to need a VCL file to configure it to work well with your installatio. Probably you need something other than the default.vcl supplied. But that is another article. If you are on Varnish 2 you should have no problem in finding something on the net. For Drupal, Pressflow’s example is a good starting point.

On this site, I did not succeed in getting anonymous comments working on cached pages with Varnish. Caching just the front page is of course possible (though you have to strip cookies under vcl_fetch, otherwise you get a ‘hitpass’ from the cache, rather than an hit). But, with the site behind Cloudflare, I found a cached front page was loading slower than an uncached page. If anyone can explain that, please let me konw!

BTW if you are installing for the first time on cPanel, check out UNIXy. I have not used them but it looks good. There are some additional complications with installing on cPanel, but they are not great. Still, given the time it takes to get the hang of the new software, the price of the cPanel plugin is probably worth it.

Leave a Reply

Your email address will not be published. Required fields are marked *