Difference between revisions of "Setup Varnish Cache"

From Brian Nelson Ramblings
Jump to: navigation, search
(Make Varnish start on Boot)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[File:Varnish cache.jpeg|150px|frameless|right|Varnish Cache Setup]]
 
==Setting up Varnish Cache with default.vcl==
 
==Setting up Varnish Cache with default.vcl==
  
Line 7: Line 8:
 
Once finished the reader should have a basic Varnish 3.0 cache up and running with the default configuration.
 
Once finished the reader should have a basic Varnish 3.0 cache up and running with the default configuration.
  
==Install Varnish YUM Repository==
+
===Install Varnish YUM Repository===
  
 
  rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
 
  rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
  
==Install Varnish with Yum==
+
===Install Varnish with Yum===
  
 
  yum install varnish -y
 
  yum install varnish -y
  
==Make Varnish start on Boot==
+
===Make Varnish start on Boot===
  
 
  chkconfig varnish on
 
  chkconfig varnish on
Line 22: Line 23:
  
 
  /etc/init.d/varnish start
 
  /etc/init.d/varnish start
 +
 +
===Configure Varnish to use Port 80===
  
 
The default installation of Varnish will start off listening to port 6081
 
The default installation of Varnish will start off listening to port 6081
Line 32: Line 35:
  
 
  VARNISH_LISTEN_PORT=80
 
  VARNISH_LISTEN_PORT=80
 +
 +
===Configure http/Apache to port 81===
  
 
Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81
 
Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81
Line 42: Line 47:
  
 
Now apache will be listing on port 81 and varnish will listen on port 80
 
Now apache will be listing on port 81 and varnish will listen on port 80
 +
 +
===Configure Varnish to Use Apache port 81===
  
 
Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.
 
Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.
Line 58: Line 65:
 
  /etc/init.d/varnish restart
 
  /etc/init.d/varnish restart
  
 +
===Lets Verify Everything is Correct===
 
Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80
 
Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80
  
Line 63: Line 71:
  
 
[[File:Varnish-setup.png|800px|frameless|Varnish Setup ]]
 
[[File:Varnish-setup.png|800px|frameless|Varnish Setup ]]
 +
 +
===Additional Articles===
 +
* [[Setup Varnish for Magento]]
 +
* [[Setup Varnish for Wordpress]]
 +
* [[Setup Varnish for MediaWiki]]
 +
* [[Setup Varnish - Multiple Domains]]
 +
* [[Setup Varnish - Multiple Ipaddress]]

Latest revision as of 06:29, 19 January 2014

Varnish Cache Setup

Setting up Varnish Cache with default.vcl

What is Varnish Cache?

Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly.

Once finished the reader should have a basic Varnish 3.0 cache up and running with the default configuration.

Install Varnish YUM Repository

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm

Install Varnish with Yum

yum install varnish -y

Make Varnish start on Boot

chkconfig varnish on

Now the basic Varnish install is complete, now lets start it

/etc/init.d/varnish start

Configure Varnish to use Port 80

The default installation of Varnish will start off listening to port 6081

You will want to adjust this to listen on port 80 so that it will cache incoming web requests.

vim /etc/sysconfig/varnish

Adjust the following value to port 80

VARNISH_LISTEN_PORT=80

Configure http/Apache to port 81

Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81

sed -i 's/80/81/g' /etc/httpd/conf/httpd.conf

Now restart apache so it will start listen on port 81

/etc/init.d/httpd restart && /etc/init.d/varnish restart

Now apache will be listing on port 81 and varnish will listen on port 80

Configure Varnish to Use Apache port 81

Now you will want to edit you default.vcl file, to tell it use 127.0.0.1:81.

vim /etc/varnish/default.vcl

Change backend to use port 81, by default its set to port 80.

 backend default {
  .host = "127.0.0.1";
  .port = "81";
}

Now one last varnish restart, and you are up and running with the default varnish installation

/etc/init.d/varnish restart

Lets Verify Everything is Correct

Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80

netstat -nptl | grep -E '80|81'

Varnish Setup

Additional Articles