First, Haproxy configuration introduction:
Second, Haproxy load Balancing algorithm Introduction:
Balance Roundrobin # Polling, soft load balancing basically has this algorithm
Balance STATIC-RR # Based on weights, it is recommended to use
Balance Leastconn # Minimum number of connections processed first, recommended use
Balance Source # Based on the request Origin IP, it is recommended to use
Balance URI # Based on the requested URI
Balance Url_param # URL parameter according to request ' balance Url_param ' requires an URL parameter name
Balance HDR (name) # Lock every HTTP request based on the HTTP request header
Balance Rdp-cookie (name) # Locks and hashes each TCP request according to the cookie (name)
Third, the user session to maintain, share:
Due to the user request after Haproxy processing forwarding to different servers, may cause session sessions are not synchronized, if you want to achieve session sharing or retention, you can use the following 3 ways:
1, based on IP address:
Configuration: Balance Source
Implementation principle: Similar to Nginx ip_hash, the user IP after the Hash comparison judgment, the request forwarded to the back-end server.
2. Cookie-based identification:
Configuration: Cookie Session_cookie Insert Indirect nocache
Implementation principle: Insert (or add prefix) the server cookie ID of the backend defined by Haproxy into the cookie that is sent to the client from the Web server side.
3, based on session recognition:
Configuration: appsession jsessionid len 5h request-learn
Implementation principle: Haproxy The session and back-end server identities generated by the backend server are present in a table in Haproxy. This table is queried first when the client requests it.
Haproxy Load Balancing Algorithm Introduction: