Summary of lvs, nginx, and haproxy transit modes

Source: Internet
Author: User
: This article mainly introduces the summary of the lvs, nginx, and haproxy transit modes. if you are interested in the PHP Tutorial, refer to it. Lvs, nginx, and haproxy are the three most common high-availability load balancing software. Since lvs and haproxy are not used in the current company's current network environment, even though they have been easy to understand and set up before, they are almost forgotten, even though the company is using nginx server load balancer, the configuration files are ctrl + c, ctrl + v, and the theoretical content of forwarding is almost forgotten. In my mind, there are only upstream, dr, and ip_hash words. We will summarize the forwarding methods of the three methods.

I. LVS forwarding mode

LVS is a four-layer high-possibility software written by Dr. Zhang Wenyu. Unlike the latter two, which support layer-7 forwarding, it is also the most stable because of its simplicity. There are three types of IP Server load balancer technologies: VS/NAT (Virtual Server via Network Address Translation), VS/TUN (Virtual Server via IP Tunneling), and VS/DR (Direct Routing ), the specific comparison between the three is shown in the table below.

II. nginx load mode

Nginx has five load algorithm modes: Round Robin, weight (weight), ip_hash, fair, and url_hash. One by one:

  1. Round Robin (default): each request is distributed to different backend servers one by one in chronological order. if the backend server is down, it can be automatically removed.
  2. Weight: specifies the polling probability. weight is directly proportional to the access ratio, which is used when the backend server performance is uneven. Configuration:
    1. Upstream bakend {
    2. Server 192.168.0.14 weight = 10;
    3. Server 192.168.0.15 weight = 10;
    4. }
  3. Ip_hash: each request is allocated based on the hash result of the access ip address. in this way, each visitor accesses a backend server in a fixed manner, which can solve the session problem. Configuration:
    1. Upstream bakend {
    2. Ip_hash;
    3. Server 192.168.0.14: 88;
    4. Server 192.168.0.15: 80;
    5. }
  4. Fair: requests are distributed based on the response time of the backend server. requests with short response time are prioritized.
    1. Upstream backend {
    2. Server server1;
    3. Server server2;
    4. Fair;
    5. }
  5. Url_hash: distribute requests based on the hash results of the access url so that each url is directed to the same backend server. the backend server is effective when it is cached. Configuration example:
    1. Upstream backend {
    2. Server squid1: 3128;
    3. Server squid2: 3128;
    4. Hash $ request_uri;
    5. Hash_method crc32;
    6. }

Note: In the fifth mode, you must add a hash statement to upstream. other parameters such as weight cannot be written in server statements. hash_method is the hash algorithm used.

The following parameters are commonly followed by the server:

  • Down indicates that the server before a ticket is not involved in the load
  • The default weight value is 1. the larger the weight value, the larger the load weight.
  • Max_fails: the default number of failed requests is 1. if the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.
  • Fail_timeout: the pause time after max_fails failed.
  • Backup: requests the backup machine when all other non-backup machines are down or busy. Therefore, this machine is under the least pressure.
3. haproxy

Haproxy is the most load algorithm among the three, there are eight, so its application scenarios are the most, the configuration is also the most flexible, the specific eight algorithms are:

① Roundrobin indicates a simple round robin, which is basically available in server load balancer;

② Static-rr, indicating that according to the weight, it is similar to the weight algorithm of nginx;

③ Leastconn indicates that at least the connection provider processes the request first, which is somewhat similar to the nginx fair. However, fair is based on the response time;

④ Source indicates the Request source IP address. This is similar to the IP_hash mechanism of Nginx. We use it as a solution to the session problem. we recommend that you pay attention to it;

⑤ Ri indicates the request URI, which is similar to the url_hash of nginx;

⑥ Rl_param indicates the request URl parameter 'balance url_param' requires an URL parameter name;

7. hdr (name) indicates locking each HTTP request based on the HTTP request header;

Extends rdp-cookie (name) indicates that each TCP request is locked and hashed based on the cookie (name.

IV. Summary

You can select the best load mode based on the actual situation of the current network application. Among the three, lvs has the best stability and the least configurability. nginx has the strongest regular matching for domain names and directory structures, while nginx has little network dependency, however, the performance is slightly worse than that of lvs and haproxy. haproxy supports virtual hosts, especially for session persistence. It has three algorithms to achieve session sharing-ip recognition (source) cookie recognition and session recognition. In addition, this software is often used in the HA solution for mysql.

The above is a summary of the lvs, nginx, and haproxy transfer modes, including some content, and hope to help those who are interested in PHP tutorials.

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.