How To Configure Pen-Load Balancer on Centos/RHEL 6x
Q. What is PEN ?
-- Install Pen to configure Load Balance server. Pen is a light weight simple load balancer. This example shows to configure on the environment like follows.
Scenario:
=======
192.168.100.229 ser5.domain.com ser5 - PEN Server
192.168.100.220 ser1.domain.com ser1 - Web Server1
192.168.100.221 ser2.domain.com ser2 - Web Server2
Step: 1. Bind Hosts File (All Servers) :
# vi /etc/hosts
192.168.100.229 ser5.domain.com ser5
192.168.100.220 ser1.domain.com ser1
192.168.100.221 ser2.domain.com ser2
-- Save & Quit (:wq)
Step: 2. Install and Configure Pen (192.168.100.229-ser5.domain.com) :
# cd /tmp
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
# yum -y install pen
# vi /etc/pen.conf
-- Paste the Following Lines :
# log file
LOGFILE=/var/log/pen.log
# output file of status
WEBFILE=/var/www/pen/webstats.html
# control port
CONTROL=127.0.0.1:10080
# max connections
MAX_CONNECTIONS=500
# listen port
PORT=80
# number of backend servers
BACKEND=2
# IP address of a backend webserver
SERVER1=192.168.100.220:80
# IP address of a backend webserver
SERVER2=192.168.100.221:80
-- Save & Quit (:wq)
Step: 3. Create init Script for Pen :
# vi /etc/rc.d/init.d/pend
#!/bin/bash
# pend: Start/Stop Pend
# chkconfig: - 90 10
# description: Pen is a light weight simple load balancer.
# pidfile: /var/run/pen.pid
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
. /etc/pen.conf
LOCKFILE="/var/lock/subsys/pen"
PID=/var/run/pen.pid
PROG=/usr/bin/pen
RETVAL=0
start() {
echo -n $"Starting Pend: "
SERVER=`grep "^SERVER" /etc/pen.conf | cut -d= -f2`
daemon $PROG -w $WEBFILE -x $MAX_CONNECTIONS -p $PID -l $LOGFILE -C $CONTROL -S $BACKEND -r $PORT $SERVER
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n $"Stopping Pend: "
killproc $PROG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $PID $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status pend
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit $?
-- Save & Quit (:wq)
Step: 4. Setting up Log Rotation :
# vi /etc/logrotate.d/pen
/var/log/pen.log {
daily
copytruncate
compress
notifempty
missingok
postrotate
/etc/rc.d/init.d/pend restart 2>&1 > /dev/null || true
endscript
}
-- Save & Quit (:wq)
# chmod 755 /etc/rc.d/init.d/pend
# service pend start
# chkconfig --add pend
# chkconfig pend on
Step: 5. Install & Configure Backend Web Server (Web-Server1 & Web-Server2) :
# yum -y install httpd httpd-devel
# cd /var/www/html
# vi index.html
<html>
<body bgcolor="black">
<marquee><font size="8" color="yellow"> This is Web-Server1...!!!</font></marquee>
</body>
</html>
-- Save & Quit (:wq)
# service httpd restart
# chkconfig httpd on
On Web-Server2 :
# yum -y install httpd httpd-devel
# cd /var/www/html
# vi index.html
<html>
<body bgcolor="black">
<marquee><font size="8" color="yellow"> This is Web-Server2...!!!</font></marquee>
</body>
</html>
-- Save & Quit (:wq)
# service httpd restart
# chkconfig httpd on
Step: 6. Now, Point Your Web Browser & Type :
http://192.168.100.229 # Pen Server IP Address.
Step: 7. Configure the tool that it's possible to watch Pen's Status :
# cp /usr/share/doc/pen-*/penstats /var/www/pen
# vi /var/www/pen/penstats
# Line No. 4: Change to:
PIDFILE=/var/run/pen.pid
# Line No. 5: Change to:
WEBFILE=/var/www/pen/webstats.html
-- Save & Quit (:wq)
Step: 8. Install Apache Server for See Pen Status :
# yum -y install httpd httpd-devel
# vi /etc/httpd/conf/httpd.conf
Chenge Listen Port to:
Listen 8080
-- Save & Quit (:wq)
# mv /etc/httpd/conf.d/pen.conf /etc/httpd/conf.d/pen.conf.bak
# vi /etc/httpd/conf.d/pen.conf
Alias /pen/ /var/www/pen/
<Directory /var/www/pen/>
DirectoryIndex penctl.cgi
Options ExecCGI
order deny,allow
deny from all
allow from 127.0.0.1 192.168.100.0/24 # IP address you permit
</Directory>
-- Save & Quit (:wq)
# service httpd restart
# chkconfig httpd on
# service pend restart
Step: 10. Run the Following Command :
# chmod 755 /var/www/pen/penstats
# /var/www/pen/penstats > /dev/null
Step: 10. Schedule in Crontab (Update by 1 minutes) :
# crontab -e
*/1 * * * * /var/www/pen/penstats > /dev/null
-- Save & Quit (:wq)
# service crond restart
Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog
Your blog has given me that thing which I never expect to get from all over the websites. Nice post guys!
ReplyDeleteGreat ppost thanks
ReplyDelete