Friday, August 28, 2009

LOAD BALANCE WEB SERVER USE POUND

This example is based on the environment below.

(1) cluster.test.vn [192.168.0.17] Pound server
(2) www.test.vn [192.168.0.18] Web server #1
(3) www2.test.vn [192.168.0.21] Web server #2

In this example, Pound server listens HTTP requests, and if requests to jpg or gif files come, they are forwarded to (2)'s server, and if requests to files except jpg or gif, they are forwarded to (3)'s server. It's also necessary to set gateway router that HTTP requests are forwared to pound server first.

[1] Install and configure Pound

[root@cluster ~]# yum -y install pound #or you download pound rpm from http://rpm.pbone.net
[root@cluster ~]#useradd -s /sbin/nologin -d /root pound
[root@cluster ~]#vi /etc/pound.cfg


# an example
# see "man pound" if you'd like to know more

#Global settings
# specify user

User "pound"
# specify group

Group "pound"
# log level (max = 5)

LogLevel 1
# send heartbeat ?/per second

Alive 30
# run as a daemon

Daemon 1

# Pound server settings
ListenHTTP
# IP of Pound server

Address 192.168.0.17

# Listen Port

Port 80

End

# Config for backend server #1

# Backend server settings
Service
# listen requests to jpg,gif

URL ".*.(jpg|gif)"
BackEnd

# server's IP

Address 192.168.0.18

# Listen Port

Port 80

End

End

# Config for backend server #2

Service
# listen requests except the one specified on #1's server

URL ".*"
BackEnd

# server's IP

Address 192.168.0.21

# Listen Port

Port 80

End

End


[root@cluster ~]#vim /etc/init.d/pound

# an example

#!/bin/bash
#
# pound: Starting Pound
#
# chkconfig: 345 98 91
# description:
HTTP/HTTPS reverse-proxy and load-balancer

# processname: pound

. /etc/rc.d/init.d/functions

pound="/usr/sbin/pound"
lockfile="/var/lock/subsys/pound"
prog="pound"
RETVAL=0

start() {

echo -n $"Starting $prog: "


daemon $pound


RETVAL=$?


echo


[ $RETVAL = 0 ] && touch $lockfile


return $RETVAL

}
stop() {

echo -n $"Stopping $prog: "


killproc $pound


RETVAL=$?


echo


[ $RETVAL = 0 ] && rm -f $lockfile


return $RETVAL

}
case "$1" in

start)


start


;;


stop)


stop


;;


restart)


stop


start


;;


status)


status $pound


;;


*)


echo "Usage: $prog {start|stop|restart|status}"


exit 1

esac

exit $?


[root@cluster ~]#chmod 755 /etc/init.d/pound
[root@cluster ~]#/etc/init.d/pound start
Starting pound: starting...[ OK ]
[root@cluster ~]#chkconfig --add pound
[root@cluster ~]#chkconfig pound on

[2] Verify load baranced or not. Upload jpg or gif file on Web Server #1 and create a html file on webserver #2 that shows a file on Web server #1 .

[root@www ~]#vim /var/www/html/index.html


[3] Access with web browser. Pound works normally.


No comments:

Post a Comment