Thursday, May 23, 2013

Integrating Varnish cache with Apache


Installing Varnish cache in cPanel server+Centos5.8

Varnish cache can be configure as a reverse apache proxy for accelarate web site access. Varnish cache stores the web pages in server's virtual memory.
Each users connection will be handled by each worker thread. I have tested this in my testing server. Here we are listrning port 80 to Varnish process and web server will handles the request in port 8080.


 # wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm
 # rpm --nosignature -i varnish-release-3.0-1.noarch.rpm
 # yum install varnish

Open /etc/sysconfig/varnish and make the changes as follows:
NFILES=131072
MEMLOCK=82000
RELOAD_VCL=1
VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_LISTEN_PORT=80
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_MIN_THREADS=2
VARNISH_MAX_THREADS=1000
VARNISH_THREAD_TIMEOUT=120
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_SIZE=1G

We need to make sure the following options are updated in this configuration file:
VARNISH_LISTEN_ADDRESS , VARNISH_LISTEN_PORT, VARNISH_VCL_CONF
VARNISH_ADMIN_LISTEN_ADDRESS,VARNISH_ADMIN_LISTEN_PORT
VARNISH_TTL,VARNISH_MIN_THREADS,VARNISH_MAX_THREADS,VARNISH_THREAD_TIMEOUT
VARNISH_SECRET_FILE,VARNISH_STORAGE

Next configuration is at /etc/varnish/default.vcl

backend b1 {
.host = "IP_Address of your server";
.port = "8080";
}

acl a1 {
"IP_Address";
}

sub vcl_recv {
if (server.ip ~ a1) {
set req.backend = b1;
}
}

Next we need to change Apache's port from 80 to 8080

]# /etc/init.d/varnish restart
Stopping Varnish Cache:                                    [  OK  ]
Starting Varnish Cache:                                    [  OK  ]

]# /etc/init.d/httpd restart

]# netstat -lpn | grep varnish
tcp        0      0 127.0.0.1:6082              0.0.0.0:*                   LISTEN      18276/varnishd    
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      18278/varnishd    
tcp        0      0 :::80                       :::*                        LISTEN      18278/varnishd



Thursday, May 2, 2013

remove IP block

If your cPanel server csf will not remove temporary / permanent block while using

csf -tr and csf -dr commands. In this situation we can remove the block using following method.

[~]# csf -g IP_ADDRESS

Chain            num   pkts bytes target     prot opt in     out     source               destination        

DENYIN           3     1178 72006 DROP       all  --  !lo    *       ip         0.0.0.0/0



Solution
 [~]#  iptables -D DENYIN 3


root@ajeesh [~]# csf -g 174.129.254.101
Chain num pkts bytes target prot opt in out source destination

LOCALOUTPUT 9 183 11076 DROP all -- * !lo 0.0.0.0/0 IP/16 Solution
root@ajeesh [~]# iptables -D LOCALOUTPUT 9