Varnish installation on Centos server is very simple :
1. Installing varnish and packages:
mk /root/varnish
cd /root/varnish
wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/x86_64/varnish-3.0.3-1.el5.centos.x86_64.rpm
wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/x86_64/varnish-libs-3.0.3-1.el5.centos.x86_64.rpm
rpm -ivh *.rpm
yum install libedit -y
Note: Current installation for x86_64 system also if libedit was not found in your repo, do wollowing:
rpm -ivh http://mirror.chpc.utah.edu/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
If all following links are not working you can download here:
varnish-3.0.3-1.el5.centos.x86_64.rpm
varnish-libs-3.0.3-1.el5.centos.x86_64.rpm
epel-release-5-4.noarch.rpm
2. Replace standard port to 80:
replace 'VARNISH_LISTEN_PORT=6081' 'VARNISH_LISTEN_PORT=80' -- /etc/sysconfig/varnish
3. You need to change Apache port from 80 to 81 (or 8081), it can be done via WHM panel Main > Server Configuration >Tweak Settings
find field Apache non-SSL IP/port and change it to 0.0.0.0:81 (or 0.0.0.0:8081) then save.
If you’ll be not able to login into WHM back, try to login via http://whm.yourdomain:81 (or http://whm.yourdomain:8081)
4. Then we need to rebuild Apache config, log in back to console and run:
/scripts/rebuildhttpdconf
5. Change Apache port for checkserverd:
replace "service[httpd]=80" "service[httpd]=81" -- /etc/chkserv.d/httpd
or
replace "service[httpd]=80" "service[httpd]=8081" -- /etc/chkserv.d/httpd
Then you need to restart chkservd via WHM panel Main > Service Configuration > Service manager and simply Save, chkservd will be restarted with new parameters.
6. Then we need to modify /etc/varnish/default.vcl, replace:
backend default {
.host = "127.0.0.1";
.port = "80";
}
to
backend default {
.host = "127.0.0.1";
.port = "81";
}
backend newbackend {
.host = "YOUR_SERVER_IP";
.port = "81";
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
sub vcl_recv {
if (server.ip == "YOUR_SERVER_IP")
{
set req.backend = newbackend;
}
else
{
set req.backend = default;
}
}
DON’T FORGET TO REPLACE “YOUR_SERVER_IP”
7 Add varnish to autostart
ln -s /etc/init.d/varnish /etc/rc3.d/S99varnish
ln -s /etc/init.d/varnishlog /etc/rc3.d/S99varnishlog
8. Restart Varnish and log deamon
/etc/init.d/varnish restart
/etc/init.d/varnishlog restart