Simple implementation of LVS load balancing

Source: Internet
Author: User

1. Theoretical part

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/62/wKioL1YcWESR1Un2AAEsQihvnlA995.jpg "title=" Lvs.png "alt=" Wkiol1ycwesr1un2aaesqihvnla995.jpg "/>

1.1, the structure of LVS

Dispatch Layer (Director):

Cluster layer (Real Server)

Shared layer

1.2, LVS Three kinds of work mode

1) Dr Mode

-MAC Layer Implementation

-Director changes the requested packet target Mac to the MAC address of the real server

-Data is returned directly to the client

2) Nat mode

-IP Layer Implementation

-Director changes the requested destination IP to the IP of the real server

-Data returned at Director to restore source IP

3) Tun Mode

-Similar to VPN implementations

-Director establishes encrypted IP tunnel forwarding to real Server

-Data is returned directly to the client

1.3, the LVS IP classification

1) VIP (Virtual IP)

-VIP Each machine needs to be configured

-IP for intranet communication and external service

2) DIP (Driector IP)

-Dip set on Driector server

-Sub-network IP, intranet IP for internal communication, external network IP for NAT mode extranet

3) RIP (Real IP)

-RIP is set on real server

-Only intranet Ip,ip only for intranet communication

1.4, the LVS scheduling algorithm:

1) Round call scheduling (Round Robin, abbreviated RR)

2) weighted round call (Weighted Round Robin, abbreviated WRR)

3) Minimum link (Least Connection, abbreviation LC)

4) Weighted least link (Weighted Least conncetions, referred to as WLC)

2. Experimental part

2.1, the experimental premise

1) host information

Dr:

Director ipaddress=10.168.0.90

VIP ipaddress=10.168.0.91

Hostname=dr

RS1:

Real ipaddress=10.168.0.94

Vip-lo ipaddress=10.168.0.91

Hostname=rs1

RS2:

Real ipaddress=10.168.0.95

Vip-lo ipaddress=10.168.0.91

Hostname=rs2

2) Yum Source

In Real Server

Yum Install-y httpd

In Director

Yum Install-y Ipvsad

2.1. NAT Mode Configuration

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/67/wKiom1YcavyxAX8lAAGlEsFs6YY431.jpg "title=" Lvs-nat.png "alt=" Wkiom1ycavyxax8laaglesfs6yy431.jpg "/>

Vim adds/usr/local/sbin/lvs_nat.sh

#! /bin/bash# director  server to turn on the route forwarding feature:  echo 1  > /proc/sys/net/ipv4/ip_forward #  disable redirection of ICMP echo 0 > /proc/sys/net/ Ipv4/conf/all/send_redirectsecho 0 > /proc/sys/net/ipv4/conf/default/send_redirectsecho  0 > /proc/sys/net/ipv4/conf/eth0/send_redirectsecho 0 > /proc/sys/net/ ipv4/conf/eth1/send_redirects# director  setting up NAT firewall iptables -t nat -fiptables -t  nat -xiptables -t nat -a postrouting -s 10.168.0.0/24  -j  masquerade# director set ipvsadmipvsadm= '/sbin/ipvsadm ' $IPVSADM  -C$IPVSADM -A -t  192.168.0.11:80 -s lc -p 300$ipvsadm -a -t 192.168.0.11:80 -r  10.168.0.94:80 -m -w 1$ipvsadm -a -t 192.168.0.11:80 -r 10.168.0.95:80  -m -w 1 

To run the script:

sh/usr/local/sbin/lvs_nat.sh

2.2. Dr Mode configuration

In Director

Vim adds/usr/local/sbin/lvs_dr.sh

#! /bin/bashecho 1 >/proc/sys/net/ipv4/ip_forwardipv=/sbin/ipvsadmvip=10.168.0.91rs1=10.168.0.94rs2= 10.168.0.95ifconfig eth0:0 $VIP broadcast $vip netmask 255.255.255.255 uproute add-host $vip Dev eth0:0$ipv-c$ipv-a-t $VIP: 80-s RR $IPV-t $vip: 80-r $rs 1:80-g-W 1$ipv-a-t $vip: 80-r $rs 2:80-g-W 1

In Real Server

Vim adds/usr/local/sbin/lvs_dr_rs.sh

#! /bin/bashvip=10.168.0.91ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up Route add-host $vip Lo:0echo "1" ;/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/ Net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/all/arp_announce

To run the script:

In Director

/usr/local/sbin/lvs_dr.sh

In Real Server

sh/usr/local/sbin/lvs_dr_rs.sh

Reference documents:

How the LVS-DR works

Http://os.51cto.com/art/201105/264303.htm

LVS Scheduling Algorithm Classification:

Http://www.apelearn.com/bbs/thread-7407-1-1.html

Arp_ignore&arp_announce parameter (dr Mode):

Http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html



This article is from the "Old Tan Linux Blog" blog, please be sure to keep this source http://cmdschool.blog.51cto.com/2420395/1702421

Simple implementation of LVS load balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.