Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Overview of Haproxy Building Web Cluster with Picture and text

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Today, what the editor shares with you is an overview of Haproxy building Web cluster graphics and text. I believe most people don't know much about it. In order to make you understand better, I summarized the following contents for you. Without saying much, let's move on.

Blog catalogue

I. Overview of Haproxy

1. HTTP request

2. Common scheduling algorithms for load balancing

3. Common Web cluster scheduler

II. Introduction of Haproxy configuration items

1. Global configuration items usually have the following configuration parameters:

2. The default configuration parameters of defaults configuration items are generally inherited by the application component. If there is no special declaration in the application component, the default configuration parameters will be installed:

3. Listen configuration items: general configuration application module parameters:

III. Parameter optimization of Haproxy

I. Overview of Haproxy

Haproxy is a popular cluster scheduling tool at present. There are many similar cluster scheduling tools, such as LVS and Nginx. Comparatively speaking, LVS has the best performance, but the construction is relatively complex; the upstream module of Nginx supports the cluster function, but the health check function of the cluster node is not strong, and the performance is not as good as Haproxy. The official website of Haproxy is http://www.haproxy.org/.

1. HTTP request

The protocol used to access a website through URL is the HTTP protocol, and such requests are generally referred to as HTTP requests. The way of HTTP request is divided into GET mode and POST mode.

When accessing a URL using a browser, the status code is returned according to the request URL. Usually, the normal status code is 2 X X, 3 X X (e.g. 200,301), and 4 X X, 5 X X (e.g. 400,500) is returned if an exception occurs. For example, accessing http://www.test.com/a.php?ld=123 is a GET request. If the access is normal, 200 status codes will be obtained from the server log. If the request is in POST mode, the ld parameter passed to a.php will still be 123, but the browser's URL will not display the following word ld=123, so it is recommended to use POST method when the form class or has a user name, password and other content to submit. No matter which way you use, the final value obtained by a.php is the same.

2. Common scheduling algorithms for load balancing

There are three most commonly used scheduling algorithms for LVS, Haproxy, and Nginx, as follows:

RR (Round Robin): dynamic weighted polling algorithm, which supports runtime adjustment of weights and slow start mechanism; supports up to 4095 back-end hosts; this is the smoothest and fairest algorithm when the processing time of the server is evenly distributed. The algorithm is dynamic, and the weight of the server that starts slowly for the instance will be adjusted during the run.

LC (Least Connections): minimum number of connections algorithm, the server with the least number of connections receives connections first. It is recommended to be used in long session scenarios, such as LDAP, SQL and other protocols, but not for short session protocols. Such as HTTP. The algorithm is dynamic, and the weight of the server that starts slowly for the instance will be adjusted during the run.

SH (Source Hashing): source address hashing algorithm, which hashes the request source IP address; model method: divide the source address hash by the total weight of the server, the server change will affect the global scheduling effect; assign it according to the result. As long as the server is normal, the same client IP address always accesses the same server. If the result of the hash varies with the number of available servers, the client is directed to a different server; the algorithm is static by default, so it is invalid to modify the server's weight at run time, but the algorithm adjusts to the change of "hash-type".

This algorithm is generally used for Tcp schemas that cannot be inserted into cookie. It can also be used in the wide area network to provide the most effective adhesion for clients who refuse to use session cookie; consistent hash: server changes only affect local scheduling; dynamic scheduling. 3. Common Web cluster scheduler

At present, the common Web cluster scheduler is divided into software and hardware, software usually uses open source LVS, Haproxy, Nginx; hardware generally use F5, but also many people use some domestic products, such as barracuda, Green League and so on.

II. Introduction of Haproxy configuration items

The configuration file for Haproxy is usually divided into three parts:

Global;defaults;listen

Global is the global configuration, defaults is the default configuration, and listen is the application component configuration. 1. Global configuration items usually have the following configuration parameters: global log 127.0.0.1 local log 127.0.0.1 local1 notice # log loghost local0 info maxconn 4096 chroot / usr/share/haproxy uid 99 gid 99 daemon 2, defaults configuration items configure default parameters, which are generally inherited by application components If there is no special declaration in the application component The default configuration parameter: defaults log global mode http option httplog option dontlognull retries 3 redispatch maxconn 2000 contimeout 5000 clitimeout 50000 will be installed Srvtimeout 50000 3 、 General configuration application module parameters of listen configuration item: listen appli4-backup 0.0.0.0 option httpchk / index.html option persist balance roundrobin server inst1 192.168.114.56 check inter 2000 fall 3 server inst2 192.168.114.56 index.html option persist balance roundrobin server inst1 81 check inter 2000 fall 3 backup III, Haproxy parameter optimization

With regard to the parameter optimization of Haproxy, several key parameters are listed below, and the suggestions for optimizing the production environment of each parameter are explained:

So much for sharing about Haproxy building Web cluster. I hope the above content can be used as a reference for everyone. If you like this article, you might as well share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report