Dr mode configuration script in lvs
1. Introduction to lvs 1.1 installation in dr Mode
Installation Details: http://www.bkjia.com/ OS /201601/410689.html.
1.2 lvs Mode
Lvs has three modes: dr, nat, and tun. Here we will first introduce the dr mode.
1.3 dr features 1) Load Balancer and all Real servers are in the same LAN segment.
2) After the Real Server processes the request, it directly returns it to the user without returning it through the scheduler.
1.4 process request process: Customer => vip => RealServer.
Response Process: RealServer => customer.
2. Configure the environment 2.1 LoadBalancerDIP: 192.168.142.20.( 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. Configure LoadBalancer in script 3.1 # 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 rewrite the MAC address of the request message and send the request packet to the realserver. # Do not change the source and target IP addresses of the packet, and then the realserver directly replies to the client, without going through the LVS scheduler, this greatly reduces the burden on 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 # portRPORT1 = 80 Usage () {echo "Usage: 'basename $ 0' (start | stop | status) "exit 1} if [$ #-ne 1]; then Usageficase $1 in start) echo "start LVS of DirectorServer" echo 1>/proc/sys/net/ipv4/ip_forward # set the vip/sbin/ifconfig eth0: 1 $ VIP broadcast $ VIP netmask 255.255.255.255 up/sbin/route add-host $ VIP dev eth0: 1 # clear ipvs table/sbin/ipvsadm-C # add lvs vip and port/sbin/ipvsadm-A-t $ VIP: $ VPORT1-s rr # add rip and port/sbin/ipvsadm-a-t $ VIP: $ VPORT1-r $ RIP1: $ RPORT1-g-w 1/sbin/ipvsadm-a-t $ VIP: $ VPORT1-r $ RIP2: $ RPORT1-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; *) UsageesacStart
# Sh lvs-dr.sh start
3.2 configure RealServer1 # mkdir-p/usr/local/lvs
# Cd/usr/local/lvs
# Vi realServer. sh
#! /Bin/sh # realServer. sh # lvs's dr mode RIP server script # VIP = 192.168.142.211 # vip's broadcastBROADCAST = 192.168.142.255 Usage () {echo "Usage: 'basename $ 0' (start | stop) "exit 1} if [$ #-ne 1]; then Usageficase $1 in start) echo "reparing 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.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 configure RealServer2 in the same way as RealServer1.
4 build web server test 1) RealServer1 and RealServer2 install and configure Nginx (detailed description: http://blog.csdn.net/clevercode/article/details/45442155)
2. Create index.html In the webserver root directory of realserver1.
# Vi index.html
If you see this page, then you know this ip is 192.168.142.130 and this page is from nginx!
3. Create index.html In the webserver root directory of realserver2.
# Vi index.html
If you see this page, then you 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 the same content.