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 live network environment, although they were briefly understood and built before, they have almost forgotten it now. As for nginx load balancing, although the company is using it, it only needs to be configured once The files are all ctrl+c, ctrl+v, and I have almost forgotten the theoretical things about forwarding. The only words that vaguely come to mind now are upstream, dr, and ip_hash. Now we will summarize the forwarding methods of the three.
LVS is a high-possibility software that works on the fourth layer written by Dr. Zhang Wensong. Unlike the latter two, it does not support seven-layer forwarding, but precisely because of its simplicity, it is the most stable. There are three IP load balancing 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.
nginx has five load algorithm modes, namely: polling, weight (weight), ip_hash, fair, url_hash. Now explain one by one:
Note: In the fifth mode, you need to pay attention to adding hash statements in upstream. Other parameters such as weight cannot be written in the server statement. hash_method is used hash algorithm. The parameters often followed by
server are as follows:
haproxy has the most loaded algorithms among the three, with eight types, so it has the most application scenarios and the most flexible configuration. The specific eight algorithms are:
①roundrobin, which means simple Polling, this is basically what load balancing has;
②static-rr, which means based on weight, is similar to nginx's weight algorithm;
③leastconn, which means the least connected person is processed first, a bit similar to nginx's fair, but fair It is based on the response time;
④source, which means based on the request source IP. This is similar to the IP_hash mechanism of Nginx. We use it as a method to solve the session problem. It is recommended to pay attention;
⑤ri, which means based on the URI of the request, similar to nginx's url_hash;
⑥rl_param, which means that 'balance url_param' requires an URL parameter name according to the requested URL parameter;
⑦hdr(name), which means that each HTTP request is locked based on the HTTP request header;
⑧rdp-cookie(name) means locking and hashing each TCP request based on cookie(name).
Specific implementation network applications can choose the best load method based on the actual situation of the object. Among the three, lvs has the best stability and the least configurability; nginx is the strongest in regular matching of domain names and directory structures. At the same time, it has less dependence on the network, but its performance is slightly worse than lvs and haproxy. ; haproxy supports virtual hosts, especially in terms of session retention. It has three algorithms to achieve session sharing - IP identification (source), cookie identification, and session identification. In addition, it does mysql This software is also often used in HA solutions.
The above has introduced a summary of the transfer modes of lvs, nginx, and haproxy, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.