Build LVS Load Balancer Cluster

Source: Internet
Author: User

Load balancer can be used with LVS scheme, but to prevent single point of failure, you can choose lvs+keepalived combination to ensure high availability

Focus : Each node synchronizes time
Ntpdate time.windows.com

1. Introduction to the Environment

Operating system: Centos6.6

Dr Tops: Ipvs management tools: ipvsadm,keepalived

Realserver tops: Nginx or Apache

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/71/5B/wKiom1XMHTuy6mSoAAB-rc_cONg598.jpg "title=" Lvs.png "alt=" Wkiom1xmhtuy6msoaab-rc_cong598.jpg "/>

first, the theoretical chapter composition of the 1.lvs cluster

The LVS server system consists of three parts

1) Load Balancer layer:

Located in the forefront of the entire system, to avoid a single point of failure is generally composed of 2 or more than 2 load scheduler

2) Server Group layer

is a group of truly service machines, real server can be: Web, Ftp, mail and so on. 4

3) shared storage tier

Provides a storage area for real servers that share storage space and content consistency

Directory is the core of the entire LVS and can only be installed on Linux and FreeBSD,

Real server can be all system platforms

2.lvs of three modes:

*NAT:

Principle: Dr received the request packet, according to the scheduling algorithm to find the corresponding RS, the destination IP of the packet is changed to RS IP, and the request is distributed to the RS,RS received the packet and processing completed, the data will be sent to dr,dr the original address of the packet to its own IP, the destination IP is changed to the client IP

Advantage: Save IP Address, because only Dr needs a public IP address

Disadvantage: When all the request packages and reply packets pass through the DR (load balancer) and the server nodes are too large, a lot of packets are processed by the load balancer slowly.

* Direct Connect route-DR:

Principle: Dr received the request packet, according to the scheduling algorithm to find the corresponding RS, the purpose of the packet Mac changed to Rs mac (because the IP is consistent), and the request was distributed to the Rs,rs received the packet and processing completed, due to IP consistent, the data is returned directly to the client

Pros: Dr is just a distribution request, and the response packet is returned directly to the customer by RS, reducing the load balancer's massive data flow, and the load balancer is no longer a system bottleneck

Disadvantage: Each machine needs a public IP,

* Tunnel-tun:

principle: (one IP packet is encapsulated in another IP packet, so it can cross the network segment.) After the DR receives the request packet, according to the scheduling algorithm to find the corresponding Rs,rs received, the message is unpacked to obtain the destination address of the VIP message, if the VIP address is configured locally, the request will be processed, processing the data directly back to the client

Advantage: If you run on the public network, you can distribute to different regions and cross the city.

3.lvs of four scheduling algorithms:

Polling (RR): In turn distributed to back-end RS in order of request

Weighted polling (WRR): Higher weights get more tasks

Minimum number of connections (LC): Dynamically creates a request on a RS with a smaller number of connections

Weighted minimum number of connections (WLC): The scheduler automatically asks for the real load situation of RS and dynamically adjusts the power

4.ipvsadm parameters

1) Add Virtual Server syntax:

Ipvsadm-a t|u|f [Vip_addr:port] [-s specify algorithm]

-A: Add

-T:TCP protocol

-U:UDP protocol

-F: Firewall tag

-D: Delete

-E: Modify

-L: View

2) Add Real server syntax

ipvsadm-a t|u|f [Vip_addr:port] [-R Rsip_addr] [-g|i|m] [-w weight]

-A: Add

-T:TCP protocol

-U:UDP protocol

-F: Firewall tag

-r: Specify Real server IP

-G:DR mode

-i:tun mode

-m:nat mode

-W: Specify Weights

-D: Delete

-E: Modify

-L: View

3) General:

IPVSADM-LN Viewing rules

Service ipvsadm Save rule

Ipvsadm-r < Path/to/somefile

4) Example:

Ipvsadm-a-T 192.168.1.10:80-s wrr ipvsadm-a-T 192.168.1.10:80-r 192.168.1.107-g-W 4ipvsadm-a-T 192.168.1.10:80- R 192.168.1.108-t-W 3
second, the actual combat chapter

1. Building the LVS

for Dr mode

1) directory:      Installation Ipvsadm     yum -y install   ipvsadm      Configuration vip    ifconfig eth0:0  192.168.1.10 broadcast 192.168.1.10 netmask 255.255.255.255        Add Routes        route add -host 192.168.1.10 dev  eth0        adding a virtual server  ipvsadm -A -t 192.168.1.10:80   -s wrr           Add back-end rs1     Ipvsadm -a -t 192.168.1.10:80  -r  192.168.1.105 -g  -w   2            Add back-end rs2     Ipvsadm -a -t 192.168.1.10:80  -r  192.168.1.106 -g  -w   2       Preservation            service ipvsadm  Save<pre name= "code"  class= "HTML" >             View            ipvsadm -ln    1) RS node:                 echo  2 > /proc/sys/net/ipv4/conf/all/arp_announce                 echo 2 > /proc/sys/net/ipv4/conf/eth0/ Arp_announce              echo 1  > /proc/sys/net/ipv4/conf/all/arp_ignore               echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore                 above configure tuning Linux kernel arp response parameters, prevent update VIP MAC address, avoid conflict        Configuration vip     ifconfig lo:0  192.168.1.10 braodcast  192.168.1.10 netmask 255.255.255.255     Add Route      route  add  -host 192.168.1.10 dev lo:0      Start Services       service httpd start



Build LVS Load Balancer Cluster

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.