Implementation of e-commerce website architecture based on LVS load Balancing cluster

Source: Internet
Author: User

Implementation of e-commerce website architecture based on LVS load Balancing cluster


Specifically how to implement e-commerce website See blog: http://13150617.blog.51cto.com/13140617/1978954


Experiment one, implement the load balancing of LVS based on NAT mode :

Prepare three hosts: one director ( Bridge network card, host network only ):

dip:192.168.199.145 vip:172.17.111.117

One backend server ( host only ): rip:192.168.199.146 configured with e-commerce website

One backend server ( host only ): rip:192.168.199.143 configured with e-commerce website

Steps:

First, the director operation:

① Installing IPVSADM:

Yum Install Ipvsadm

② to see if the kernel supports IPVS modules:

Grep-i-C "Ipvs"/boot/config-3.10.0-514.el7.x86_64

③ plus three records:

turn on a the the virtual service for the port is dispatched WRR

Ipvsadm-a-T 172.17.111.117:80-s WRR

Configuration Web Service back end Real server is Nat working mode, weighted to 1

Ipvsadm-a-T 172.17.111.117:80-r 192.168.199.146:80-m-W 1

Ipvsadm-a-T 172.17.111.117:80-r 192.168.199.143:80-m-W 1

650) this.width=650; "src=" https://s2.51cto.com/oss/201711/04/b5d9da77633d427ac72b91422b064ab3.jpg "style=" float: none; "title=" image 1.jpg "alt=" b5d9da77633d427ac72b91422b064ab3.jpg "/>

④ turn on route forwarding vim/etc/sysctl.conf

Net.ipv4.ip_forward=1

Sysctl-p

Two, two background server operation:

Add Routing route add default GW 192.168.199.145

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/04/99c144b96d0d117c00c6504523de84d9.jpg "title=" Picture 2.jpg "style=" Float:none; "alt=" 99c144b96d0d117c00c6504523de84d9.jpg "/>

third, browser access: http://172.17.111.117

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/04/b6f6b6fd8b37dc2db57371f90b992abf.jpg "title=" Picture 3.jpg "style=" Float:none; "alt=" b6f6b6fd8b37dc2db57371f90b992abf.jpg "/>

Testing: Creating HTML pages on two back-end servers, testing load Balancing

Client Access: Curl http://172.17.111.117/index.html

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/04/fc973c66483f873e81b78a153309f560.jpg "title=" Picture 4.jpg "style=" Float:none; "alt=" fc973c66483f873e81b78a153309f560.jpg "/>

experiment two, realize based on DR mode of LVS Load Balancing :

Prepare three hosts: Bridge mode

A director,dip:172.17.111.117 vip:172.17.111.111

A backend server, rip:172.17.111.234 vip:172.17.111.111

A backend server, rip:172.17.111.222 vip:172.17.111.111

Steps:

first, the director operation:  

① Installing IPVSADM:

Yum Install Ipvsadm

② to see if the kernel supports IPVS modules:

Grep-i-C "Ipvs"/boot/config-3.10.0-514.el7.x86_64

③ Configure the VIP to the local NIC alias eth0:0, and only broadcast itself:

Ifconfig eth0:0 172.17.111.111 broadcast 172.17.111.111 netmask 255.255.255.255 up

650) this.width=650; "src=" https://s3.51cto.com/oss/201711/04/d3cc334674e8eb877d9f8545ed8163a0.jpg "style=" float: none; "title=" Image 5.jpg "alt=" d3cc334674e8eb877d9f8545ed8163a0.jpg "/>

④ Add route: Route add-host 172.17.111.111 Dev eth0:0

650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/04/ee21fa26b645c5fd75845f376ebd4711.jpg "title=" Picture 6.jpg "style=" Float:none; "alt=" ee21fa26b645c5fd75845f376ebd4711.jpg "/>

⑤ add three records:

turn on a the the virtual service for the port is dispatched in WRR:

Ipvsadm-a-T 172.17.111.111:80-s WRR

Configuration Web Service back end Real Server to be DR working mode, weighted to 1

Ipvsadm-a-T 172.17.111.111:80-r 172.17.111.234:80-g-W 1

Ipvsadm-a-T 172.17.111.111:80-r 172.17.111.222:80-g-W 1

650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/04/67a0ef3d1be741954fe61d571ac625fa.jpg "title=" Picture 7.jpg "style=" Float:none; "alt=" 67a0ef3d1be741954fe61d571ac625fa.jpg "/>

Second, the background server operation:

① Configure the VIP to the local loopback network card lo, and only broadcast itself:

Ifconfig lo:0 172.17.111.111 broadcast 172.17.111.111 netmask 255.255.255.255 up

650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/04/f6243280774445584641582cdaf50c9a.jpg "title=" Picture 8.jpg "style=" Float:none; "alt=" f6243280774445584641582cdaf50c9a.jpg "/>

② Configure local loopback NIC routing:

Route Add-host 172.17.111.111 lo:0

650) this.width=650; "src=" https://s1.51cto.com/oss/201711/04/a30083ebb0528fefda57b489277b51ec.jpg "style=" float: none; "title=" Image 9.jpg "alt=" a30083ebb0528fefda57b489277b51ec.jpg "/>

③ ignores IP-to-Mac mismatch issues:

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

Third, test: Set up the HTML page on two back-end servers, test load Balancer

Client Access: Curl http://172.17.111.111/index.html

650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/04/af18fa177fb206840b9eaaec64638383.jpg "title=" Picture 10.jpg "style=" Float:none; "alt=" af18fa177fb206840b9eaaec64638383.jpg "/>

Experiment three, achieve the LVS persistent connection (based on the Dr Experiment above):

Function: Regardless of which scheduler the Ipvs uses, it is capable of always sending requests from the same IP address to the same RS within a specified time frame, which is implemented through the LVS Persistent connection template, which is independent of the scheduling method.

Steps:

① mark on iptables, Mark Port 80 as a  

Iptables-t mangle-a prerouting-d 172.17.111.111-p tcp--dport 80-j MARK--set-mark 99

② mark on Iptables, Mark Port 443 as 99

Iptables-t mangle-a prerouting-d 172.17.111.111-p tcp--dport 443-j MARK--set-mark 99

③ Cleanup of previous Virtual server table records: IPVSADM-C

④ building a virtual service based on 99th mark on LVS

Ipvsadm-a-F 99-s rr-p

⑤ setting up Backend service addresses

Ipvsadm-a-F 99-r 172.17.111.234-g

Ipvsadm-a-F 99-r 172.17.111.222-g

⑥ test: Use different host tests, same host access to page unchanged

650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/04/c45861c05608b1c6b0028fe72ab80ec9.jpg "title=" Picture 11.jpg "style=" Float:none; "alt=" c45861c05608b1c6b0028fe72ab80ec9.jpg "/> 650" this.width=650; "src=" Https://s1.51cto.com/oss/201711/04/94e9f11b1735c0dd1f067ac7de3e10b1.jpg "title=" Picture 12.jpg "style=" Float:none; "alt = "94e9f11b1735c0dd1f067ac7de3e10b1.jpg"/>

Experiment four, to achieve health monitoring (based on the above Dr and persistent connection experiment):

First, the installation Kit:

RZ ldirectord-3.9.6-0rc1.1.1.x86_64.rpm

Yum Localinstall ldirectord-3.9.6-0rc1.1.1.x86_64.rpm

Second, edit the configuration file:

① Copy profile template

cp/usr/share/doc/ldirectord-3.9.6/ldirectord.cf/etc/ha.d/

② Edit the configuration file, modify the following lines

Vim/etc/ha.d/ldirectord.cf

Quiescent=no

No means to delete the Realserver record that is not detected, yes to set its weight to 0 instead of deleting the record.

Virtual=172.17.111.111:80

REAL=172.17.111.234:80 Gate 2 2 means weight

REAL=172.17.111.222:80 Gate 2

Scheduler=wrr

Request= "Ok.html"

Receive= "OK"

Third, clear all records of the Virtual server table: Ipvsadm-c

Iv. Start-up service: Systemctl start Ldirectord. The Virtual server table is automatically generated

650) this.width=650; "src=" https://s4.51cto.com/oss/201711/04/7879722fe3d8aa08860f975f6cec9a6c.jpg "style=" float: none; "title=" Image 13.jpg "alt=" 7879722fe3d8aa08860f975f6cec9a6c.jpg "/>

Prepare the ok.html page on the Realserver backend server, and the content is OK.

650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/04/2c6e72d324f1bc94d2aae564da4c5e8f.jpg "title=" Picture 14.jpg "style=" Float:none; "alt=" 2c6e72d324f1bc94d2aae564da4c5e8f.jpg "/>

VII. testing: When modifying one of the Realserver's ok.html, the machine's records are less in the Virtual server table, and the machine is not accessed by the client.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/04/fc3b3df8d60d74ee3d2ac088278499dc.jpg "title=" Picture 15.jpg "style=" Float:none; "alt=" fc3b3df8d60d74ee3d2ac088278499dc.jpg "/>

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/04/e6858a35fce68c7d50951f70661153c1.jpg "title=" Picture 16.jpg "style=" Float:none; "alt=" e6858a35fce68c7d50951f70661153c1.jpg "/>

When the ok.html page is restored, the records in the Virtual server table are added, and the client is able to access the server.

650) this.width=650; "src=" https://s5.51cto.com/oss/201711/04/c91d4b520938151f9609dbb7d2d59d5a.jpg "style=" float: none; "title=" Image 17.jpg "alt=" C91d4b520938151f9609dbb7d2d59d5a.jpg "/>

650) this.width=650; "src=" https://s4.51cto.com/oss/201711/04/4f78d6a8ffb9f13a3f4dd74f47595a1f.jpg "style=" float: none; "title=" Image 18.jpg "alt=" 4f78d6a8ffb9f13a3f4dd74f47595a1f.jpg "/>


Thanks for browsing, if in doubt, please leave a message.

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0080.gif "alt=" J_0080.gif "/>

Implementation of e-commerce website architecture based on LVS load Balancing 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.