Front server:
OS: CentOS 5.6
ip: eth0 192.168.1.17 netmask 255.255.255.0
Gateway: 192.168.1.1
Rear Server:
OS: CentOS 5.6
server one: 192.168.1.101 netmask 255.255.255.0
server two: 192.168.1.102 netmask 255.255.255.0
server three: 192.168.1.103 netmask 255.255.255.0
Gateway: 192.168.1.1
Front server configuration
1. Install ipvsadm/apache on front server
linuxdba -->yum install ipvsadm
linuxdba -->yum install httpd
2. setup lvs
linuxdba -->vi /etc/init.d/lvstun
#!/bin/bash
# description: start|stop TUN
VIP=192.168.1.18
RIP1=192.168.1.101
RIP2=192.168.1.102
RIP3=192.168.1.103
/etc/init.d/functions
case "$1" in
start)
echo "Start LVS of DirectorServer TUN"
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
/sbin/ipvsadm -C
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
/sbin/ipvsadm
;;
stop)
echo "Stop LVS of DirectorServer DR"
echo "0"> /proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
/sbin/ifconfig tunl0 down
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
3. run lvs script
linuxdba -->/etc/init.d/lvs start
Rear server configuration
1. Create and run the following script on each rear server.
linuxdba -->vi /etc/init.d/lvsrstun
#!/bin/bash
# description : start realserver TUN
VIP=192.168.1.18
/etc/init.d/functions
case "$1" in
start)
echo "Start LVS of RealServer TUN"
/sbin/ifconfig tunl0 $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
echo "1">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig tunl0 down
echo "Close LVS of RealServer TUN"
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
2. Install/start apache service on each server
one -->yum install httpd
one -->service httpd start
two -->yum install httpd
two -->service httpd start
three -->yum install httpd
three -->service httpd start
3. Write test script on each server
server one:
one -->vi /var/www/html/index.html
192.168.1.101 one
server two:
two -->vi /var/www/html/index.html
192.168.1.102 two
server three:
three -->vi /var/www/html/index.html
192.168.1.103 three
Test
open the following test site on the web browser and refresh for some times:
http://192.168.1.18/index.html
view the results:
linuxdba --> ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.18:http rr
-> three.org:http Tunnel 1 0 5
-> two.org:http Tunnel 1 0 7
-> one.org:http Tunnel 1 0 6
linuxdba -->