Front server:
OS: CentOS 5.6
ip:
eth0 192.168.1.17 netmask 255.255.255.0
eth0:0 10.0.0.1 netmask 255.255.255.0
Gateway: 192.168.1.1
Rear Server:
OS: CentOS 5.6
server one: 10.0.0.101 netmask 255.255.255.0
server two: 10.0.0.102 netmask 255.255.255.0
server three: 10.0.0.103 netmask 255.255.255.0
Gateway: 10.0.0.1
Front server configuration
1. Configure the front server as gateway server, run the following script.
#!/bin/bash
/sbin/modprobe ip_tables
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
/sbin/iptables -F
/sbin/iptables -F -t nat
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
echo "1" > /proc/sys/net/ipv4/ip_forward
######### eth0 wlan ##########
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -s 0/0 -d 0/0 -j ACCEPT
2. Install ipvsadm/apache on front server
linuxdba -->yum install ipvsadm
linuxdba -->yum install httpd
3. setup lvs
linuxdba -->vi /etc/init.d/lvs
#!/bin/bash
#LVS script (NAT)
VIP=192.168.1.17
RIP1=10.0.0.101
RIP2=10.0.0.102
RIP3=10.0.0.103
case "$1" in
start)
echo "1">/proc/sys/net/ipv4/ip_forward
/sbin/iptables -F
/sbin/ipvsadm -C
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -m
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -m
/sbin/ipvsadm -a -t $VIP:80 -r $RIP3 -m
/sbin/ipvsadm
;;
stop)
echo "0">/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
4. run lvs script
linuxdba -->/etc/init.d/lvs start
Rear server configuration
1. 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
2. Write test script on each server
server one:
one -->vi /var/www/html/index.html
10.0.0.101 one
server two:
two -->vi /var/www/html/index.html
10.0.0.102 two
server three:
three -->vi /var/www/html/index.html
10.0.0.103 three
Test
open the following test site on the web browser and refresh for some times:
http://192.168.1.17
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 linuxdba.org:http rr
-> three.org:http Masq 1 0 3
-> two.org:http Masq 1 0 3
-> one.org:http Masq 1 0 3
linuxdba -->