1 Dr Mode Introductioninstallation of 1.1 LVs
Installation Detailed: http://blog.csdn.net/CleverCode/article/details/50586957.
1.2 LVs Mode
LVS has three modes of Dr,nat,tun. This first introduces Dr mode.
1.3 Dr Features1) Load balancer and all real servers are on the same LAN segment.
2) Real server returns the request directly to the user after processing it, and does not need to be returned through the scheduler.
1.4 Processing ProcessRequest process: Customer = VIP = Realserver.
Response process: Realserver = customer.
2 Configuring the Environment2.1 LoadBalancerdip:192.168.142.133 (eth0).
vip:192.168.142.211 (eth0:1).
2.2 RealServer1dip:192.168.142.130 (eth0).
2.3 RealServer2dip:192.168.142.131 (eth0).
3 Configuration Scripts3.1 Configuring LoadBalancer# mkdir-p/usr/local/lvs
# Cd/usr/local/lvs
# VI lvs-dr.sh
#!/bin/sh# lvs-dr.sh## LVS Dr Mode LVs Server Script # # # # VIP and RIP must be in the same network segment. VS/DR by rewriting the MAC address of the request message, sending the requested packet to Realserver, # does not change the packet source and destination IP address, and then realserver directly reply to the client, no longer through the LVS scheduler, this greatly reduces the burden of LVS. # Set the VIP and portvip=192.168.142.211vport1=80# set the rip and port# webrip1=192.168.142.130rip2=192.168.142.131# por Trport1=80usage () {echo ' Usage: ' basename $ ' (start|stop|status) ' Exit 1}if [$#-ne 1];then usageficase ' in Start) echo "Start LVS of Directorserver" Echo 1 >/proc/sys/net/ipv4/ip_forward # set T He vip/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up/sbin/route add-host $VIP Dev E Th0:1 # Clear Ipvs table/sbin/ipvsadm-c # Add LVS VIP and Port/sbin/ipvsadm -a-t $VIP: $VPORT 1-s RR # Add rip and Port/sbin/ipvsadm-a-t $VIP: $VPORT 1-r $RIP 1: $RPORT 1-g-W 1/sbin/ipvsadm-a-T $VIP: $VPORT 1-r $RIP 2: $RPORT 1-g-W 1/sbin/ipvsAdm-l-N;; Stop) echo "Close LVS directorserver"/sbin/ipvsadm-c/sbin/ifconfig eth0:1 down;; Status)/sbin/ipvsadm-l-n;; *) Usageesac
Start
#sh lvs-dr.sh Start
3.2 Configuring RealServer1# mkdir-p/usr/local/lvs
# Cd/usr/local/lvs
# VI realserver.sh
#!/bin/sh# realserver.sh## LVS Dr Mode rip Server script # VIP=192.168.142.211#VIP ' s broadcastbroadcast=192.168.142.255 Usage ( {echo "Usage: ' basename $ ' (start|stop)" Exit 1}if [$#-ne 1];then usageficase "in Start) echo" R Eparing for Real Server "echo" 1 ">/proc/sys/net/ipv4/conf/all/arp_ignore echo" 2 ">/proc/sys/net/ipv4 /conf/all/arp_announce echo "1" >/proc/sys/net/ipv4/conf/eth0/arp_ignore echo "2" >/proc/sys/net/ipv4/ Conf/eth0/arp_announce/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $BROADCAST Up/sbin/route Add-host $VIP Dev lo:0;; Stop)/sbin/ifconfig lo:0 down echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc /sys/net/ipv4/conf/all/arp_announce echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_ignore echo "0" >/proc/ Sys/net/ipv4/conf/eth0/arp_announce echo "Stop Real Server";; *) Usageesac
Start
#sh realserver.sh Start
3.3 Configuring RealServer2Configure the RealServer1.
4 Setting up a Web server test
1) RealServer1 and RealServer2 installation and configuration Nginx (detailed: http://blog.csdn.net/clevercode/article/details/45442155)
2) Establish index.html in RealServer1 Web server root directory
# VI Index.html
If you see this page,then know this IP is 192.168.142.130 and this page is from nginx!
3) Establish index.html in RealServer2 Web server root directory
# VI Index.html
If you see this page,then know this IP is 192.168.142.131 and this page is from nginx!
4) Configure host or DNS. Point my.domain.com to vip:192.168.142.211.
5) Refresh the page and you will see a different inline.
Dr Mode configuration script in LVs