LVS Persistent Connection

Source: Internet
Author: User

Lvs Persistent Connections

In simple words, the meaning of conversational retention, we know a few ways to maintain the session, a brief introduction of one of the better understanding:

Session Stickiness (session Hold): Using the sh algorithm,the SH algorithm automatically maintains a hash table in the kernel, which uses the source IP of each request The address is hashed as a key, and the address of the RS to which the request arrives is the value. In subsequent requests, each request passes through this Hashtable, and if the request has a key value in the hash table, direct to a specific RS, if not, it will be reborn into a key value so that subsequent requests are directed. However, this method is not an ideal method in time, and is only an algorithm.

so there is the LVS persistent connection function,LVS Persistence

This method realizes that regardless of which scheduling method is used, the persistent connection function is guaranteed to be within the specified time range, from the same IP requests will always be directed to the same RS, and multiple services can be bound after the unified scheduling.

In more detail, when the user requests to reach the director . Regardless of the scheduling method, you can implement a request for the same service to always be directed to the same RS within a specified time range . There is a lvs persistent connection template in the director, which records the source of each request, the RS to be dispatched to, the length of maintenance, andso on, so that when a new request comes in, First check if there is a record in this template (the record in this table has a time limit), if the record does not time out, then use the RS pointed to by the record , if it is a time-out record or a new request, it will be dispatched to a specific RS according to the scheduling algorithm , Then add the scheduled records to this table. This does not conflict with the SH algorithm,and the LVS persistent connection checks the back-end RS for load conditions when a new request is reached, which is the more granular scheduling and session hold method.

The command is:ipvsadm-a-t|-u|-f service-address-s SCHEDULER [-P [#]] ( the time of the default p is seconds)

Lvs Persistent Connection also has a role, roughly speaking, if a director is followed by two clusters, one is a Web server cluster, and one is a mail server cluster. When the request arrives at the director , there is a choice to dispatch to the appropriate cluster. There are three kinds of situations:

PPC: persistent per port ; The persistent connection takes effect only for a single Cluster service ( after each record in the director's persistent connection template plus the tag of the specified cluster), and if there are multiple cluster services, each service is individually and persistently dispatched;

Example 1:V1 for director,V2, V3 for Real server , all on both RS httpd,mysql-server,telnet-server(this load balancer is performed on the DR type of the different network segments that were previously built)

Two units V2,V3 on all open httpd,telnet-server,mysql-server

Service httpd Start

Service mysqld Start

Cchkconfig Telnet on

Service Xientd Start

in the V1 setting up load balancing for Web service persistent connections

Ipvsadm–a–t 172.16.50.12:80–s Rr-p

Ipvsadm–a–t 172.16.50.12:80–r192.168.0.21:80–g

Ipvsadm–a–t 172.16.50.12:80–r192.168.0.31:80–g

Access on physical machines, persistent problem-free

in the Configure The Telnet service to load balance on a persistent connection V1

Ipvsadm–a–t 172.16.50.12:23–s Rr-p

Ipvsadm–a–t 172.16.50.12:23–r192.168.0.21:23–g

Ipvsadm–a–t 172.16.50.12:23–r192.168.0.31:23–g

in the Create user passwords on V2, V3,respectively

Useradd CentOS

echo CentOS | passwd--stdin CentOS

Persistent problem-free connection using telnet

PCC: persistent for each client ; the persistent connection takes effect for all services; When defining a Cluster service, the target port of its TCP or UDP protocol should use 0;

Example 2: a 1 -based example of client-side persistence

rules for clearing example 1

Ipvsadm–c

Setting client-side persistence rules

Ipvsadm–a–t 172.16.50.12:0–s RR

Ipvsadm–a–t 172.16.50.12:0–r 192.18.0.21-g

Ipvsadm–a–t 172.16.50.12:0–r 192.18.0.31–g

no problem with Web service testing and Telnet testing

PFWM: per FWM durable : The persistent connection takes effect for all services defined under the same FWM.

Example 3: Based on example 1 of the DR type load balancing, try the Unified Scheduling of the 443 and the port

HTTP service and HTTPS service configuration is not redundant,V1 for director,V2,V3 provide http, HTTPS,telnet service

in the set rules on V1:

Iptables–a prerouting–t mangle–d172.16.50.12–p tcp–dport 80–j Mark–set-mark 10

Iptables–a prerouting–t mangle–d172.16.50.12–p tcp–dport 443–j Mark–set-mark 10

Iptables–a prerouting–t mangle–d172.16.50.12–p tcp–dport 23–j Mark–set-mark 10

Ipvsadm–a–f 10–s RR

Ipvsadm–a–f 10–r 192.168.0.21–g

Ipvsadm–a–f 10–r 192.168.0.31–g

so let's try it ^_^


LVS Persistent Connection

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.