Home > HowTo, Linux > How to install varnish

How to install varnish

December 29th, 2009 Leave a comment Go to comments

Updatede version of this howto

I have used a lot os Squid, but now we need a reverse cache solution.
And the best one out there is an Open Source software called Varnish.

How to install (tested on CentOs /RedHat)
Directly from .rpm:

Or download and compile from source:
# cd /usr/local
# 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
#  ./configure
Varnish will store run-time state in $localstatedir/varnish; you may
want to tune this using configure’s –localstatedir parameter.
Additional configure options of interest:
–enable-developer-warning                         enable strict warnings (default is NO)
–enable-debugging-symbols                         enable debugging symbols (default is NO)
–enable-werror                                      use -Werror (default is NO)

# make
# make install

How to Start Varnish
# varnishd -a :80 -T localhost:23 -f /usr/local/etc/varnish/intra.vcl -s file,/var/cache/varnish
-a Where it will listen
-T Terminal for administrastion, telnet to it and type help, many nice cmds
-f Your .vcl file
-s Type of cache storage system and location
Remember to check more option, man varnishd

Check if its really running
# ps aux |grep varni

Now lets load configuration and start it
# telnet localhost
Connected to localhost.localdomain (
Escape character is ‘^]’.
#    vcl.load intra /usr/local/etc/varnish/intra.vcl
200 13
#    VCL compiled.
#    vcl.use intra

200 0
#    start
300 22
Child in state running

So we how do we now its working?
Just check “Cache Hits”, it means the varnish server is serving the web pages and
its not going to the backend web server.
Another way:
Check the HTTP Header (I use Firefox Addon Firebug)
if you see two sets of numbers then its coming from the cache
X-Varnish    979505999  979505985

# telnet localhost
200 3262
27  Client connections accepted
0  Connection dropped, no sess
117  Client requests received
48  Cache hits
0  Cache hits for pass
55  Cache misses

I wrote a script to start/stop/restart/status/stats of the varnish daemon
just download here and copy into /etc/init.d/
Edit the script and change the SITEID to the name of your .vcl file, then do:
# adduser varnish
# chkconfig –add varnish
# chkconfig –level 234 varnish on
# service varnish stats

Location of Files.:
Main Program:
Config Files:
Example Config files:

Good references:






  1. Kermit Tensmeyer
    March 11th, 2010 at 13:34 | #1

    I’ve used several sets of reverse proxy.

    The simplest to set up is Apache. The proxy modules can be used with both reverse and forward proxy. http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

    IBM Tivoli Security products include WebSeal which is primarly a reverse proxy with ACL controls on sections within a target web tree.

    Squid also has a very good solution.. http://wiki.squid-cache.org/SquidFaq/ReverseProxy

  1. July 20th, 2011 at 12:29 | #1
  2. July 20th, 2011 at 18:03 | #2