Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as heavily consumed APIs.
Below steps explain how to install and configure Varnish cache server.
Operating System: CentOS 6.4
Hostname: server
IP Address: 192.168.1.6
Step 1: Install the varnish package
[root@server ~]# rpm -ivh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.el5.centos.noarch.rpm
[root@server ~]# yum install -y varnish
Step 2: Start apache server
[root@server ~]# /etc/init.d/httpd start
Starting httpd: [ OK ]
[root@server ~]# chkconfig --level 35 httpd on
Step 3: Configuring Varnish
[root@server ~]# vi /etc/varnish/default.vcl
Change the below parameters
From:
backend default {
.host = "127.0.0.1";
.port = "80";
To:
backend default {
.host = "127.0.0.1";
.port = "88";
Save and Exit (:wq!)
[root@server ~]# vi /etc/sysconfig/varnish
#Uncomment the below settings and change the parameter
VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_MIN_THREADS=1
VARNISH_MAX_THREADS=1000
VARNISH_THREAD_TIMEOUT=120
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_SIZE=512M
VARNISH_STORAGE=โmalloc,${VARNISH_STORAGE_SIZE}โ
VARNISH_TTL=120
Save and Exit (:wq!)
Step 4: Apache Configuration
Change the apache listen port from 80 to 88
[root@server ~]# vi /etc/httpd/conf/httpd.conf
From:
Listen 80
To:
Listen 88
Step 5: Run apache and varnish daemon
[root@server ~]# /etc/init.d/varnish start
[root@server ~]# /etc/init.d/varnish status
varnishd (pid 2587) is running...
[root@server ~]# chkconfig --level 35 varnish on
[root@server ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@server ~]# chkconfig --level 35 httpd on
Step 6: Test your website
[root@server ~]# curl -I http://localhost
HTTP/1.1 200 OK
Server: Apache/2.2.15 (CentOS)
Last-Modified: Sun, 12 Apr 2015 07:15:32 IST
ETag: "3942-2a-51381c35c67f1"
Content-Type: text/html; charset=UTF-8
Content-Length: 42
Accept-Ranges: bytes
Date: Sun, 12 Apr 2015 07:16:55 IST
X-Varnish: 612706973
Age: 0
Via: 1.1 varnish
Connection: keep-alive
[root@server ~]# varnishlog
[root@server ~]# varnishstat
Enjoy… Cheers ๐