Howto Setup Varnish

 Updated Version of this howto

Varnish is a awesome Reverse Proxy, for caching websites and improves its performance in a polish varnish way.
To setup follow the instructions (tested on CentOS

yum update
yum install ncurses-devel
make clean
mkdir /usr/local/src/varnish-2.0.5
mkdir /opt/logs
mkdir /var/lib/varnish
vim /etc/fstab
tmpfs /var/lib/varnish tmpfs nosuid,noatime,nodiratime,size=500M 0 0
cd /
unzip varnish
tar -xvf varnish2.tar
chown root:root -R /usr/local/src/varnish-2.0.5
cd /usr/local/src/varnish-2.0.5
make clean
make && make install

cd /usr/local/
ls -ltr
mv varnish varnish-2.0.5
ln -s varnish-2.0.5/ varnish

(add both varnishd,varnishdncsa files to /etc/init.d/)

vim /etc/sysconfig/iptables
:PREROUTING ACCEPT [393136:23556287]
:POSTROUTING ACCEPT [24626907:1397282388]
:OUTPUT ACCEPT [24626907:1397282388]
-A PREROUTING -i eth0 -p tcp -m tcp –dport 80 -j REDIRECT –to-port 81
service iptables restart
iptables -t nat -L

( copy varnish and varnish_hour to /etc/logrotate.d both )
edit the crontab
crontab -e
# VARNISH Log Rotation
0-59/5 * * * * [ ! -f /var/run/ ] && /usr/sbin/logrotate /etc/logrotate.d/varnish || /usr/local/bin/
1 * * * * [ ! -f /var/run/ ] && /usr/sbin/logrotate /etc/logrotate.d/varnish_hour || /usr/local/bin/

(edited 22/07)
Will also need to do:
1. Add the varnish bin to path
2. install ncurses
yum install ncurses
3. compile varnishstat
cd /usr/local/src/varnish-2.0.5/bin/varnishstat
make all
make install
4. copy to bin
cp /usr/local/src/varnish-2.0.5/bin/varnishstat /usr/local/varnish/bin
5. Run the command:

Leave a Reply

Your email address will not be published. Required fields are marked *