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 configuration and load balancing algorithm

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

The following gives you an overview of Haproxy configuration and load balancing algorithm, hoping to give you some help in practical application. Load balancing involves a lot of things, and there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

1. Haproxy configuration introduction:

HaProxy configuration (haproxy.cfg) is divided into five parts (five major components), which can be configured as needed.

Five components: global, defaults, frontend, backend, listen

1. Global: the parameter is process-level, usually related to the operating system (OS). These parameters are generally set only once, and if the configuration is correct, there is no need to modify the configuration again.

2. Defaults: configure the default parameters, which can be configured to the frontend,backend,listen component.

3. Frontend: the front-end virtual node that receives the request. Frontend can directly specify the backend of the backend (which can be dynamically selected) according to the rules.

4. Backend: the configuration of the backend service cluster is a real CVM. A Backend corresponds to one or more physical servers.

5. Combination of listen:Frontend and Backend.

2. Introduction of Haproxy load balancing algorithm:

Balance roundrobin # polling, soft load balancer basically have this algorithm balance static-rr # according to the weight, it is recommended to use balance leastconn # least connectors to deal with first, it is recommended to use balance source # according to the request source IP It is recommended to use balance uri # according to the requested URIbalance url_param # based on the requested URl parameter 'balance url_param' requires an URL parameter namebalance hdr (name) # to lock every HTTP request balance rdp-cookie (name) # according to the HTTP request header # to lock and hash each TCP request according to cookie (name)

Third, the user Session maintains and shares:

Due to the problem that Session sessions may be out of sync after user requests are forwarded to different servers after Haproxy processing, if you want to achieve session sharing or persistence, you can use the following three ways:

1. Based on IP address:

Configuration: balance source

Implementation principle: IP_Hash, which is similar to Nginx, forwards the request to the back-end server after comparing the user IP with Hash.

2. Based on Cookie recognition:

Configuration: cookie SESSION_COOKIE insert indirect nocache

The principle of implementation: insert (or add a prefix) the back-end server COOKIE ID defined by haproxy into the Cookie sent to the client by the Web server.

3. Based on Session recognition:

Configuration: appsession JSESSIONID len 64 timeout 5h request-learn

Implementation principle: Haproxy stores the session generated by the back-end server and the identity of the back-end server in a table in haproxy. This table is queried when requested by the client.

After reading the above overview of Haproxy configuration and load balancing algorithm, if you have anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineer to answer, the technical engineer has more than ten years of experience in the industry.

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