Lvs-nat Model Demo

Source: Internet
Author: User

Project background: LVS is the abbreviation for Linux virtual server, that is, the Lvs-nat model is a model of load balancing technology, so let's take a look at this lvs-nat.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/E5/wKiom1bbnhGjgNUYAAAeshPqyTQ482.png "title=" capture. PNG "alt=" Wkiom1bbnhgjgnuyaaaeshpqytq482.png "/> As shown, the role of director is the Load Balancer Scheduler, located between the client and Realserver, If the external request message is a Director-defined Cluster service, it will use its own well-defined scheduling algorithm, which is sent to the back of the Realserver via NAT address translation, Realserver receives and replies and then passes through the dip and uses NAT address translation to reach the client. In addition, Realserver is usually a private address, and data transmission communication is implemented only in each node.

Tentative external client IP is CIP


When the client requests the message arrives the director, the original IP is CIP, the target IP is the VIP, once the director discovers the client request is a Cluster service, uses the pre-defined scheduling algorithm, through the NAT address transformation, arrives at the backend one realserver, Assuming the Realserver1 is selected, the original IP is CIP, the target IP is RIP1, when RIP1 received, and then reply, at this time the original IP is RIP1, the target IP is CIP, when the message arrives Director,director and then through the NAT address translation, The destination IP is unchanged, the original IP is changed to VIP, and then sent out, because CIP does not request RIP1, if not converted, CIP will not receive this message, so the last step is required.


Let's take a concrete demonstration:

Client CIP (that is, native windows): 169.254.179.60

VIP: 169.254.179.1

DIP: 192.168.2.140

RIP1: 192.168.2.141

RIP2: 192.168.2.143



Operating environment VMware Workstation 9 redhat6.2


Note: To avoid other distractions, turn off the 3 iptables and set the SELinux to 0.


1 Installing the Ipvsadm:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/E4/wKioL1bbo-jzA0-gAAAdhbf4hC4753.png "title=" rpm. PNG "alt=" wkiol1bbo-jza0-gaaadhbf4hc4753.png "/> I use the Mount disc rpm installation, of course, can also be installed with Yum.


2 Defining the Cluster service

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7C/E4/wKioL1bbqK-QBSWAAAALSm3tzAw654.png "title=" Ipvsa.png "alt=" Wkiol1bbqk-qbswaaaalsm3tzaw654.png "/>-A means that the Cluster service is defined,-T represents a TCP protocol-based connection, and 169.254.179.1:80 indicates that the 169.254.17 9.1 of 80 ports are defined as cluster services, and the-s RR indicates that its scheduling algorithm is polling, that is, the client changes once per visit realserver

3 Adding Realserver

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7C/E4/wKioL1bbpVSgIf36AAAMgGF6f_k239.png "title=" Ipvs 141.PNG "alt=" wkiol1bbpvsgif36aaamggf6f_k239.png "/> 650" this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/ 7c/e4/wkiol1bbpwojpznnaaak_y2a8n4040.png "title=" Ipvs 143.PNG "alt=" Wkiol1bbpwojpznnaaak_y2a8n4040.png "/> Note: Because the picture is blocked by the word, there is also a-m parameter on the last side of the command, which represents the NAT model in LVS.

4 on Realserver1 and Realserver2 respectively on the httpd service, respectively set up a different home page, for testing the distinction, and the gateway point to dip

realserver1::650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M01/7C/E4/ Wkiol1bbpeyhc0siaaacuturb0k996.png "title=" 141 httpd. PNG "alt=" Wkiol1bbpeyhc0siaaacuturb0k996.png "/>650) this.width=650; src=" http://s5.51cto.com/wyfs02/M00/7C/E5 /wkiom1bbqfvxwkgoaaatpsk5fu0364.png "title=" 141 index. PNG "alt=" Wkiom1bbqfvxwkgoaaatpsk5fu0364.png "/>650) this.width=650; src=" http://s1.51cto.com/wyfs02/M02/7C/E4 /wkiol1bbpjoiai6laaaleeryuse478.png "title=" 141 route. PNG "alt=" Wkiol1bbpjoiai6laaaleeryuse478.png "/>


realserver2:650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M00/7C/E5/ Wkiom1bbpedczbxfaaaajvdv_cg098.png "title=" 143 httpd. PNG "alt=" Wkiom1bbpedczbxfaaaajvdv_cg098.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7C/E4/wKioL1bbqpjSGHjvAAAWXOK1c78903.png "title=" 143 Indix. PNG "alt=" Wkiol1bbqpjsghjvaaawxok1c78903.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/E4/wKioL1bbpnuCtGAuAAATQOTcNHQ240.png "style=" float: none; "Title=" 143 route. PNG "alt=" Wkiol1bbpnuctgauaaatqotcnhq240.png "/>

5 Turn on the director's Network card forwarding function

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/E5/wKiom1bbqNnBdcamAAAT-eQqIhA148.png "title=" Ipforward. PNG "alt=" Wkiom1bbqnnbdcamaaat-eqqiha148.png "/> 6 test Connection in directory first Realserver

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7C/E4/wKioL1bbqXyB819FAAAZK7MAL0s033.png "title=" Director exam. PNG "alt=" Wkiol1bbqxyb819faaazk7mal0s033.png "/>

7 View defined Cluster service 650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/7C/E5/wKiom1bbqWmiE2psAAAfZInZGBU567.png " title= "Ipvs-l-n.png" alt= "Wkiom1bbqwmie2psaaafzinzgbu567.png"/>


8 Open IE Browser on Windows, enter VIP address

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7C/E5/wKiom1bbqomhWm1DAAA8dpcV4KU023.png "title=" 1.PNG " alt= "Wkiom1bbqomhwm1daaa8dpcv4ku023.png"/>

9 Refresh Web page and view 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7C/E5/wKiom1bbqrnz2qADAAA5b-M2Ff0639.png "title = "2.PNG" alt= "Wkiom1bbqrnz2qadaaa5b-m2ff0639.png"/>

Through the page we can clearly see the conversion of the homepage, after the page will be refreshed after the Realserver1 and Realserver2 two home page conversion, this is the previous Director defines the Cluster service when the-S RR definition of the polling algorithm used.


10 View the director's Cluster connection status. : 650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/E4/wKioL1bbrAuw6StDAAAiP5xhfg8397.png "title=" Ipvs- L--stats. PNG "alt=" Wkiol1bbrauw6stdaaaip5xhfg8397.png "/>

From the display we can see the response of Realserver1 and Realserver2, incoming messages and outgoing messages, and the number of bytes in and out.



Troubleshooting process: The process of configuration because I forgot to point the Realserver gateway to the dip, resulting in realserver messages can not be sent out, so it has not been shown, so please pay attention to this problem.





Summary: Through the operation of the Lvs-nat model, we can feel the director again in the connection between the client and the Realserver role, the client request message and Realserver reply message all need to pass director, so the cluster scale is large, The director may seem a little tired.

This article is from the "11254923" blog, please be sure to keep this source http://11264923.blog.51cto.com/11254923/1748037

Lvs-nat Model Demo

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.