Install Setup Varnish Cache in CentOS 6.5

Setup, configure and Install Varnish Cache server 3.0.5

in CentOS 6.5

You can also use this guide within your CentOS 5.x.x and 6.x.x versions.

Varnish cache server 3.0.5 is the latest stable release. Centos 6.5 is latest stable release. I installed this in my company VPS so i decide to share with needed peoples who actually just miss-understood its simple configuration.

Just follow the Steps and you will get the results.

First install latest version RPM by run the following command

If you are on RHEL and CentOS 5 or a compatible distribution, use

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

For RHEL and CentOS 6 and compatible distributions, use
 

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

and then run

yum install varnish

Once it installed successfully you need to run the followng command.

chkconfig --level 345 varnish on

Now you just need to first Finalise two thing.
1. Change the Apache port from 80 to 8080
2. Define the webserver or you can say you Main server IP within Varnish configuration file in /etc/sysconfig/varnish


EDIT FILE:

nano /etc/sysconfig/varnish

You will find this part in the file which is "Alternative 3" example that varnish by default use. its best and optimise setting. Just notet the changes that i made like Port and IP in the below area. you need to made it with your own IP.
 

## Alternative 3, Advanced configuration## See varnishd(1) for more information.### Main configuration file. You probably want to change it:)

VARNISH_VCL_CONF=/etc/varnish/default.vcl
### Default address and port to bind to## Blank address means all IPv4 and IPv6 interfaces, otherwise specify## a host name, an IPv4 dotted quad, or an IPv6 address inbrackets.
VARNISH_LISTEN_ADDRESS=11.22.33.44
VARNISH_LISTEN_PORT=80

Notice two last line with IP it was before like this

#VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=6081

Remove the hash # and define VPS Main IP here on which Apache run. once done, hit Control+O to save then Control+X to exit from nano.

Now open second Varnish default.vcl file for defining the port for Apache connectivity.

EDIT FILE:

nano /etc/varnish/default.vcl

Find this part in the file

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

change the port 80 to 8080. hit Control+O to save then Control+X to exit from nano.

Now your Varnish cache web accelerator is configure on port 80 and connect with Apache server on port 8080. Now we only need to configure Apache on port 8080 on localhost IP than main VPS IP.

Open Apache default configuration file:

nano /etc/httpd/conf/httpd.conf

and change your IP with 127.0.0.1 and port with 8080. it will exactly look like this below image after the change.

listen-port-8080.jpg

once done, hit Control+O to save then Control+X to exit from nano.

inCase, you use virtual host so you need to change the virtual host IP and port same like above image.

Now its time to restart Both services for effect. First Apache service and after that Varnish service. so run the following commands.

service httpd restart
service varnish restart

Now run the following command to check Varnish is work fine OR not.

curl -I http://www.vmakerhost.com

change vmakerhost.com with your website that run from the same server.

Output should be like

HTTP/1.1200 OK
Server:ApacheSet-Cookie: 
session_id=fb2dede70fee22fac1b5924f0d1bc362; path=/; domain=vmakerhost.com; 
httponlyVary:Accept-EncodingContent-Type: text/html;charset=UTF-8Date:Sat,25Jan201418:32:27 GMT
X-Varnish:1600569958Age:0Via:1.1 varnish
Connection: keep-alive

You can notice it shows "Via: 1.1 varnish" that proof varnish works abslutely fine.

Few varnish usefull commands for performance check and advance things check.


For Varnish performance check, RUN

varnishstat

Common commands with description

Quote

# varnishstat : Provides all the info you need to spot cache misses and errors.
# varnishhist : Provides a histogram view of cache hits/misses.
# varnishlog : Provides detailed information on requests.
# varnishtop : It reads varnishd shared memory logs and presents a most commonly occurring log entries.
# varnishadm : Command-line varnish administration used to reload vcl and purge urls.

  • Email, SSL
  • 7 Users Found This Useful
Was this answer helpful?

Related Articles

Changing Server Hostname

To change your hostname, enter the following command as root: $ hostname...

cPanel: Unactive License File

cPanel may spit out a "Unactive License File" error when new IP addresses or added or when your...

How do I know what server I am on?

You can find out what server you are on using two different ways, each one revealing which server...

Migrating Accounts to your server

Most control panels have built in control panel to control panel migration tools that you can...

Howto Re-Install cPanel/WHM and DirectAdmin

To Re-Install cPanel: 1. Reformat your VPS (rebuild) 2. You need to ensure that yum is...

Powered by WHMCompleteSolution