Centos6 使用pen 实现web tcp 负载均衡
(1) rackspace-jon [192.168.58.154] – Pen Server
(2) rackspace-nfs01 [192.168.58.152] – Web Server#1
(3) rackspace-nfs02 [192.168.58.153] – Web Server#2
[root@rackspace-jon ~]# yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos-mirror.magsnet.net
* extras: centos-mirror.magsnet.net
* updates: centos-mirror.magsnet.net
Setting up Install Process
epel-release-6-8.noarch.rpm | 14 kB 00:00
Examining /var/tmp/yum-root-G_GHvp/epel-release-6-8.noarch.rpm: epel-release-6-8.noarch
Marking /var/tmp/yum-root-G_GHvp/epel-release-6-8.noarch.rpm to be installed
Resolving Dependencies
–> Running transaction check
—> Package epel-release.noarch 0:6-8 will be installed
–> Finished Dependency ResolutionDependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
epel-release noarch 6-8 /epel-release-6-8.noarch 22 kTransaction Summary
======================================================================================================================================
Install 1 Package(s)Total size: 22 k
Installed size: 22 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : epel-release-6-8.noarch 1/1
Verifying : epel-release-6-8.noarch 1/1Installed:
epel-release.noarch 0:6-8Complete!
[root@rackspace-jon ~]# sed -i -e “s/enabled=1/enabled=0/g” /etc/yum.repos.d/epel.repo
[root@rackspace-jon ~]# yum –enablerepo=epel install pen
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/metalink | 5.7 kB 00:00
* base: centos-mirror.magsnet.net
* epel: mirrors.nayatel.com
* extras: centos-mirror.magsnet.net
* updates: centos-mirror.magsnet.net
epel | 4.4 kB 00:00
epel/primary_db | 6.2 MB 00:03
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package pen.x86_64 0:0.23.0-1.el6 will be installed
–> Processing Dependency: libGeoIP.so.1()(64bit) for package: pen-0.23.0-1.el6.x86_64
–> Running transaction check
—> Package GeoIP.x86_64 0:1.5.1-5.el6 will be installed
–> Finished Dependency ResolutionDependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
pen x86_64 0.23.0-1.el6 epel 71 k
Installing for dependencies:
GeoIP x86_64 1.5.1-5.el6 epel 21 MTransaction Summary
======================================================================================================================================
Install 2 Package(s)Total download size: 21 M
Installed size: 42 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): GeoIP-1.5.1-5.el6.x86_64.rpm | 21 MB 00:11
(2/2): pen-0.23.0-1.el6.x86_64.rpm | 71 kB 00:00
————————————————————————————————————————————–
Total 1.7 MB/s | 21 MB 00:12
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : EPEL (6) <epel@fedoraproject.org>
Package: epel-release-6-8.noarch (@/epel-release-6-8.noarch)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : GeoIP-1.5.1-5.el6.x86_64 1/2
Installing : pen-0.23.0-1.el6.x86_64 2/2
Verifying : pen-0.23.0-1.el6.x86_64 1/2
Verifying : GeoIP-1.5.1-5.el6.x86_64 2/2Installed:
pen.x86_64 0:0.23.0-1.el6Dependency Installed:
GeoIP.x86_64 0:1.5.1-5.el6Complete!
Lets Start Configure PEN.
[root@rackspace-jon ~]# vi /etc/pen.conf
###################################
#WRITE BY MUHAMMAD ZEESHAN BHATTI #
#Sr. Linux System Administrator #
#################################### 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
SERVER1=192.168.58.152:80# IP address of a backend
SERVER2=192.168.58.153:80:wq!
Next we can make Stratup Script for Pen.
[root@rackspace-jon ~]# 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.confLOCKFILE=”/var/lock/subsys/pen”
PID=/var/run/pen.pid
PROG=/usr/bin/penRETVAL=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 $?:wq!
Next we can Set Logrotate Setting.
[root@rackspace-jon ~]# vi /etc/logrotate.d/pen
# this is an example
/var/log/pen.log {
daily
copytruncate
compress
notifempty
missingok
postrotate
/etc/rc.d/init.d/pend restart 2>&1 > /dev/null || true
endscript
}:wq!
[root@rackspace-jon ~]# chmod 755 /etc/rc.d/init.d/pend
[root@rackspace-jon ~]# /etc/rc.d/init.d/pend start
Starting Pend: [ OK ][root@rackspace-jon ~]# chkconfig –add pend
[root@rackspace-jon ~]# chkconfig pend on
Verify pen logs
[root@rackspace-jon ~]# tail -f /var/log/pen.log
127.0.0.1 1405627723 192.168.58.153 GET / HTTP/1.1
127.0.0.1 1405627739 192.168.58.152 GET / HTTP/1.1
Great Pen is Running.
WEB SERVER 01
[root@rackspace-nfs01 ~]# yum isntall httpd
Loaded plugins: fastestmirror
No such command: isntall. Please use /usr/bin/yum –help
[root@rackspace-nfs01 ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nayatel.com
* extras: mirrors.nayatel.com
* updates: mirrors.nayatel.com
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.8 MB 00:03
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.2.15-29.el6.centos will be updated
–> Processing Dependency: httpd = 2.2.15-29.el6.centos for package: httpd-devel-2.2.15-29.el6.centos.x86_64
—> Package httpd.x86_64 0:2.2.15-31.el6.centos will be an update
–> Processing Dependency: httpd-tools = 2.2.15-31.el6.centos for package: httpd-2.2.15-31.el6.centos.x86_64
–> Running transaction check
—> Package httpd-devel.x86_64 0:2.2.15-29.el6.centos will be updated
—> Package httpd-devel.x86_64 0:2.2.15-31.el6.centos will be an update
—> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be updated
—> Package httpd-tools.x86_64 0:2.2.15-31.el6.centos will be an update
–> Finished Dependency ResolutionDependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Updating:
httpd x86_64 2.2.15-31.el6.centos updates 824 k
Updating for dependencies:
httpd-devel x86_64 2.2.15-31.el6.centos updates 151 k
httpd-tools x86_64 2.2.15-31.el6.centos updates 73 kTransaction Summary
======================================================================================================================================
Upgrade 3 Package(s)Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): httpd-2.2.15-31.el6.centos.x86_64.rpm | 824 kB 00:00
(2/3): httpd-devel-2.2.15-31.el6.centos.x86_64.rpm | 151 kB 00:00
(3/3): httpd-tools-2.2.15-31.el6.centos.x86_64.rpm | 73 kB 00:00
————————————————————————————————————————————–
Total 1.0 MB/s | 1.0 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Updating : httpd-tools-2.2.15-31.el6.centos.x86_64 1/6
Updating : httpd-2.2.15-31.el6.centos.x86_64 2/6
Updating : httpd-devel-2.2.15-31.el6.centos.x86_64 3/6
Cleanup : httpd-devel-2.2.15-29.el6.centos.x86_64 4/6
Cleanup : httpd-2.2.15-29.el6.centos.x86_64 5/6
Cleanup : httpd-tools-2.2.15-29.el6.centos.x86_64 6/6
Verifying : httpd-2.2.15-31.el6.centos.x86_64 1/6
Verifying : httpd-tools-2.2.15-31.el6.centos.x86_64 2/6
Verifying : httpd-devel-2.2.15-31.el6.centos.x86_64 3/6
Verifying : httpd-2.2.15-29.el6.centos.x86_64 4/6
Verifying : httpd-tools-2.2.15-29.el6.centos.x86_64 5/6
Verifying : httpd-devel-2.2.15-29.el6.centos.x86_64 6/6Updated:
httpd.x86_64 0:2.2.15-31.el6.centosDependency Updated:
httpd-devel.x86_64 0:2.2.15-31.el6.centos httpd-tools.x86_64 0:2.2.15-31.el6.centosComplete!
[root@rackspace-nfs01 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.168.58.152 for ServerName
[ OK ]we can verify httpd logs to load balning is working.
[root@rackspace-nfs01 ~]# tail -f /var/log/httpd/access_log192.168.58.154 – – [19/Jul/2014:11:09:34 +0500] “GET /pen/westatus HTTP/1.1” 404 285 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:11:36 +0500] “GET / HTTP/1.1” 403 4958 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:11:36 +0500] “GET /icons/powered_by_rh.png HTTP/1.1” 404 301 “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:11:55 +0500] “GET / HTTP/1.1” 403 4958 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:12:02 +0500] “GET / HTTP/1.1” 403 4958 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:12:03 +0500] “GET / HTTP/1.1” 403 4958 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:12:03 +0500] “GET /icons/powered_by_rh.png HTTP/1.1” 404 301 “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:16:50 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:17:51 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:18:13 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
————————————————————————————————————————————
2.168.58.154 – – [19/Jul/2014:11:22:05 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”Great Working Fine. First Request Pen Server send on Port server1 port 80.
WEB SERVER 02
[root@rackspace-nfs02 ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nayatel.com
* extras: mirrors.nayatel.com
* updates: mirrors.nayatel.com
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.8 MB 00:02
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.2.15-29.el6.centos will be updated
–> Processing Dependency: httpd = 2.2.15-29.el6.centos for package: httpd-devel-2.2.15-29.el6.centos.x86_64
—> Package httpd.x86_64 0:2.2.15-31.el6.centos will be an update
–> Processing Dependency: httpd-tools = 2.2.15-31.el6.centos for package: httpd-2.2.15-31.el6.centos.x86_64
–> Running transaction check
—> Package httpd-devel.x86_64 0:2.2.15-29.el6.centos will be updated
—> Package httpd-devel.x86_64 0:2.2.15-31.el6.centos will be an update
—> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be updated
—> Package httpd-tools.x86_64 0:2.2.15-31.el6.centos will be an update
–> Finished Dependency ResolutionDependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Updating:
httpd x86_64 2.2.15-31.el6.centos updates 824 k
Updating for dependencies:
httpd-devel x86_64 2.2.15-31.el6.centos updates 151 k
httpd-tools x86_64 2.2.15-31.el6.centos updates 73 kTransaction Summary
======================================================================================================================================
Upgrade 3 Package(s)Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): httpd-2.2.15-31.el6.centos.x86_64.rpm | 824 kB 00:00
(2/3): httpd-devel-2.2.15-31.el6.centos.x86_64.rpm | 151 kB 00:00
(3/3): httpd-tools-2.2.15-31.el6.centos.x86_64.rpm | 73 kB 00:00
————————————————————————————————————————————–
Total 957 kB/s | 1.0 MB 00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Updating : httpd-tools-2.2.15-31.el6.centos.x86_64 1/6
Updating : httpd-2.2.15-31.el6.centos.x86_64 2/6
Updating : httpd-devel-2.2.15-31.el6.centos.x86_64 3/6
Cleanup : httpd-devel-2.2.15-29.el6.centos.x86_64 4/6
Cleanup : httpd-2.2.15-29.el6.centos.x86_64 5/6
Cleanup : httpd-tools-2.2.15-29.el6.centos.x86_64 6/6
Verifying : httpd-2.2.15-31.el6.centos.x86_64 1/6
Verifying : httpd-tools-2.2.15-31.el6.centos.x86_64 2/6
Verifying : httpd-devel-2.2.15-31.el6.centos.x86_64 3/6
Verifying : httpd-2.2.15-29.el6.centos.x86_64 4/6
Verifying : httpd-tools-2.2.15-29.el6.centos.x86_64 5/6
Verifying : httpd-devel-2.2.15-29.el6.centos.x86_64 6/6Updated:
httpd.x86_64 0:2.2.15-31.el6.centosDependency Updated:
httpd-devel.x86_64 0:2.2.15-31.el6.centos httpd-tools.x86_64 0:2.2.15-31.el6.centosComplete!
[root@rackspace-nfs02 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.168.58.153 for ServerName
[ OK ]now we can verify httpd access to 2nd request pen server send on where..
[root@rackspace-nfs02 tmp]# tail -f /var/log/httpd/access_log
192.168.58.154 – – [19/Jul/2014:11:10:35 +0500] “GET /pen/westatus HTTP/1.1” 404 285 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:11:37 +0500] “GET /icons/apache_pb.gif HTTP/1.1” 200 2326 “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:11:37 +0500] “GET /favicon.ico HTTP/1.1” 404 289 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:11:56 +0500] “GET /icons/powered_by_rh.png HTTP/1.1” 404 301 “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:12:02 +0500] “GET /icons/powered_by_rh.png HTTP/1.1” 404 301 “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:12:04 +0500] “GET /icons/apache_pb.gif HTTP/1.1” 304 – “http://192.168.58.154/” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36”
192.168.58.154 – – [19/Jul/2014:11:16:24 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:17:04 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:18:03 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
192.168.58.154 – – [19/Jul/2014:11:18:17 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”
——————————————————————————————————————————-
192.168.58.154 – – [19/Jul/2014:11:24:44 +0500] “GET / HTTP/1.1” 403 4958 “-” “ELinks/0.12pre5 (textmode; Linux; 134×31-2)”4Great That’s Load Blancer Working Perfectly Fine.
目录 返回
首页