Introduction of Load Balancer cluster, LVS introduction, LVS scheduling algorithm, Lvsnat mode construction

Source: Internet
Author: User
Tags haproxy

Introduction to load Balancing clusters
  • Main open source software LVs, keepalived, Haproxy, Nginx, etc.
  • The LVS belong to 4 layer (network OSI 7 layer model), Nginx belongs to 7 layer, Haproxy can be considered as 4 layer, can also be used as 7 layer
  • The Keepalived load balancing function is actually the LVS
  • LVS This 4-tier load balancer can distribute other ports except 80, such as MySQL, while Nginx supports only Http,https,mail,haproxy and MySQL.
  • In comparison, the 4-layer LVS is more stable, can withstand more requests, and nginx this 7-layer more flexible, can achieve more personalized requirements LVS Introduction
  • LVS is developed by Chinese Zhangwensong
  • Popularity is no less than Apache httpd, TCP/IP-based routing and forwarding, high stability and efficiency
  • The latest version of LVS is based on Linux kernel 2.6 and has not been updated for many years
  • LVS has three common patterns: NAT, DR, IP Tunnel
  • A core role in the LVS architecture is called the Dispatcher (Load balance), which is used to distribute the user's requests, as well as many servers that handle user requests (Real server, RS)
  • LVS NAT Mode
    • This model is implemented using the Iptables NAT table
    • After the user's request to the dispatcher, the requested packet is forwarded to the back-end RS via a preset iptables rule.
    • RS needs to set the gateway as the Distributor's intranet IP
    • The data packets that are requested by the user and the packets returned to the user are all passed through the dispatcher, so the dispatcher becomes a bottleneck, so the volume of the request cannot be too large, usually tens of thousands of units, unless the Gigabit fiber Lotus High Configuration
    • In NAT mode, the RS and the Distributor communicate through the intranet, only need the Distributor has the public IP, so the comparison of saving public IP resources
  • LVS IP tunnel mode
    • This mode requires a common IP configuration on the Distributor and all RS, we call it VIP
    • The target IP requested by the client is the VIP, and after the dispatcher receives the request packet, the packet is processed and the target IP is changed to the IP of Rs so that the packet is on the RS
    • After the RS receives the packet, it restores the original packet so that the target IP is the VIP, because the VIP is configured on all RS, so it will be considered as its own, directly returned to the user, without having to go through the dispatcher
  • LVS Dr Mode
    • This mode also requires a common IP configuration on the Distributor and all RS, which is the VIP
    • Unlike IP tunnel, it modifies the MAC address of the packet to the MAC address of the RS.
    • After the RS receives the packet, it restores the original packet so that the target IP is the VIP, because the VIP is configured on all RS, so it will be considered as its own, directly returned to the user without the need to pass the dispatcher LVS scheduling algorithm
  • Polling Round-robin abbreviated RR, user request come over, distribute evenly to RS
  • Weighted polling Weight Round-robin WRR, high weight RS multi-distribution
  • Minimum connection least-connection LC, few links, priority distribution
  • Weighted minimum connection Weight least-connection WLC
  • The minimum connection based on locality locality-based Least Connections LBLC
  • Locally-based minimal connection with replication locality-based Least Connections with Replication LBLCR
  • Destination Address hash dispatch Destination Hashing DH
  • Source Address Hash Dispatch source Hashing Shlvs NAT mode build
  • Preparatory work
    • Three machines
    • Dispatcher, also known as the Scheduler (dir)
    • Intranet: 21.128, Extranet: 110.130 (VMware Host-only mode)
    • Rs1
    • Intranet: 21.129, set gateway to 21.128
    • Rs2
    • Intranet: 21.130, set gateway to 21.128
    • Execute on all three machines
    • Systemctl Stop Firewalld; SYSTEMC Disable FIREWALLD
    • Yum Install-y iptables-services
    • Systemctl start Iptables-service; Iptables-f; Service Iptables Save
  • Nat Mode build
    • install Ipvsadm on dir
    • yum install-y ipvsadm
    • write scripts on dir, Vim/usr/local/sbin/lvs_nat. The sh//content is as follows
        #! enable route forwarding on/bin/bash# director server echo 1 >/proc/sys/net/ipv4/ip_forward# turn off ICMP redirection echo 0 >/ Proc/sys/net/ipv4/conf/all/send_redirectsecho 0 >/proc/sys/net/ipv4/conf/default/send_redirects# Pay attention to differentiate the NIC name, Amin two NICs are ens33 and Ens37echo 0 >/proc/sys/net/ipv4/conf/ens33/send_redirectsecho 0 >/proc/sys/net/ipv4/conf/ ens37/send_redirects# director Set NAT firewall Iptables-t nat-fiptables-t nat-xiptables-t nat-a postrouting-s 192.168.21.0/ 24-J masquerade# Director set ipvsadmipvsadm= '/usr/sbin/ipvsadm ' $IPVSADM-c$ipvsadm-a-t 192.168.110.130:80-s wlc-p 3$IP Vsadm-a-T 192.168.110.130:80-r 192.168.21.129:80-m-W 1$ipvsadm-a-T 192.168.110.130:80-r 192.168.21.130:80-m-W 1< /code> 
        [[email protected] ~]# sh/usr/local/sbin/lvs_nat.sh  
  • Test
    • Installation of Nginx on both RS
    • Set two RS homepage, make a distinction, that is to say, directly curl two RS IP, get different results
      [[email protected] ~]# vim /usr/share/nginx/html/index.html[[email protected]nux02 ~]# curl localhostakuilinux-02[[email protected] ~]# vim /usr/share/nginx/html/index.html[[email protected] ~]# curl localhostakuilinux-03
    • Browser access 192.168.142.147, multiple visits several times to see the difference in results
      [[email protected] ~]# curl 192.168.110.130akuilinux-02[[email protected] ~]# curl 192.168.110.130akuilinux-02[[email protected] ~]# curl 192.168.110.130akuilinux-03[[email protected] ~]# curl 192.168.110.130akuilinux-02[[email protected] ~]# curl 192.168.110.130akuilinux-03
      Extended
  • Three models of LVs detailed
  • vs several algorithms
  • About Arp_ignore and Arp_announce
  • Related to the LVS principle

Introduction of Load Balancer cluster, LVS introduction, LVS scheduling algorithm, Lvsnat mode construction

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.