Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2348398
  • 博文数量: 609
  • 博客积分: 10061
  • 博客等级: 上将
  • 技术积分: 5920
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-25 08:30
文章分类

全部博文(609)

文章存档

2010年(13)

2009年(39)

2008年(558)

我的朋友

分类: LINUX

2008-09-13 12:01:01

This example is based on follwing environmet.

 
(1) lan.server-linux.info   [192.168.0.20]  - Pen Server

(2) ns.server-linux.info    [192.168.0.17]  - Web Server #1

(3) [192.168.0.18]  - Web Server #2


 
[1]     Install and configure Pen

[root@lan ~]# wget

[root@lan ~]# tar zxvf pen-0.18.0.tar.gz

[root@lan ~]# cd pen-0.18.0

[root@lan pen-0.18.0]# ./configure

[root@lan pen-0.18.0]# make

[root@lan pen-0.18.0]# checkinstall
# create RPM

[root@lan pen-0.18.0]# cd /usr/src/redhat/RPMS/i386

[root@lan i386]# rpm -Uvh pen-0.18.0-1.i386.rpm

Preparing...
################################ [100%]

  pen
################################ [100%]

[root@lan i386]# cd

[root@lan ~]# vi /etc/rc.d/init.d/pen
# make scripts

 
# an example

#!/bin/bash
#
# Pen: Starting Pen
#
# chkconfig: 345 93 92
# description:
Simple load-balancer

# processname: pen
 
. /etc/rc.d/init.d/functions
 
pen="/usr/local/bin/pen"
lockfile="/var/lock/subsys/pen"
prog="pen"
RETVAL=0
 
# PID file

PID=/var/run/pen.pid-80
# log file

LOGFILE=/var/log/pen.log
# control port

CONTROL=localhost:10080
# max connections

MAX_CONNECTIONS=500
# port

PORT=80
# number of servers

SERVERS=2
# IP of a server #1

SERVER1=192.168.0.17:80
# IP of a server #2

SERVER2=192.168.0.18:80
 
start() {
  echo -n $"Starting $prog: "
  daemon $pen -x $MAX_CONNECTIONS -S $SERVERS -p $PID -l $LOGFILE -C $CONTROL -r $PORT $SERVER1 $SERVER2
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && touch $lockfile
  return $RETVAL
}
stop() {
  echo -n $"Stopping $prog: "
  killproc $pen
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f $lockfile
  return $RETVAL
}
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  restart)
  stop
  start
  ;;
  status)
  status $pen
  ;;
  *)
  echo "Usage: $prog {start|stop|restart|status}"
  exit 1
esac
 
exit $?

 
[root@lan ~]# vi /etc/logrotate.d/pen

 
# an example

/var/log/pen.log {
   daily
   copytruncate
   compress
   notifempty
   missingok
   postrotate
     /etc/rc.d/init.d/pen restart 2>&1 > /dev/null || true
   endscript
}

[root@lan ~]# chmod 755 /etc/rc.d/init.d/pen

[root@lan ~]# /etc/rc.d/init.d/pen start
Starting pen:     [  OK   ]

[root@lan ~]# chkconfig --add pen

[root@lan ~]# chkconfig pen on


[2]     Access to Pen server with web browser. A backend server answers normally like below. 



[3] Stop httpd on a server answering now and access to pen server again. Another backend server answers normally like below.




[4]     Configure a tool that shows status of Pen from web browser.

[root@lan ~]# vi /etc/rc.d/init.d/pen

# add some lines in a scripts that is made in [1] section

# line 16: specify html file

WEBFILE=/var/www/html/pen/index.html

PID=/var/run/pen.pid-80
LOGFILE=/var/log/pen.log
 
# add options

daemon $pen -w $WEBFILE -x $MAX_CONNECTIONS -S $SERVERS -p $PID -l $LOGFILE -C $CONTROL -r $PORT $SERVER1 $SERVER2
 
[root@lan ~]# cp /usr/local/doc/pen/penstats /usr/local/bin/

[root@lan ~]# vi /usr/local/bin/penstats
 
#!/bin/sh
 
PENHOME=/home/ulric/Projekt/pen
PIDFILE=/var/run/pen.pid-80
# change

WEBFILE=/var/www/html/pen/index.html
# change

 
# This will make pen save its stats
kill -USR1 `cat $PIDFILE`
 
# We don't know how long it will take; wait a few seconds
sleep 2
 
# And display the results
echo "Content-type: text/html"
echo
cat $WEBFILE
 
[root@lan ~]# /etc/rc.d/init.d/pen restart

Stopping pen:  [  OK  ]
Starting pen:  [  OK  ]

[root@lan ~]# chmod 755 /usr/local/bin/penstats

[root@lan ~]# /usr/local/bin/penstats  # run

[root@lan ~]# crontab -e
 
*/5 * * * * /usr/local/bin/penstats


[5]     Access to an URL you set. httpd is also needed to run, of course.


阅读(1866) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~