Haproxy Detailed study Notes

Source: Internet
Author: User
Tags haproxy rsyslog

HAProxy: Implements an event-driven, single-process model that supports tens of thousands of of concurrent connections to provide highly available, load-balanced, and proxy service solutions for TCP and HTTP applications, especially for high-load Web sites that require a durable connection or a 7-tier processing mechanism


Proxy (HTTP):
Forward Proxy:
Reverse proxy:

Agent role: Web caching (acceleration), reverse proxy, content routing (forwarding requests to a specific server based on traffic and content type, etc.), transcoding device;

Add via header on the proxy server;

The role of Caching:
Reduce redundant content transmission;
Save bandwidth and alleviate network bottleneck;
Reduced request pressure on the original server;
Reduced transmission Latency

Yum-y install Haproxy, installing Haproxy rpm-ql haproxy, see which packages are installed, find the main profile/etc/haproxy/haproxy.cfg

Global Configuration segment:

Remove global configuration segments, others are proxy configuration segments

chroot switch The root directory, Haproxy are running in/var/lib/haproxy to increase haproxy security

Pidfile Specify the main process file Maxconn default maximum number of connections user runs Haproxy group with which group runs the Haproxy daemon run bit daemon stats The socket diagram is explained in the Memory access data without the need for a TCP connection to improve operational performance)

The first log means that all logs are recorded to the local machine, output through the LOCAL2 device, so you have to go to/etc/rsyslog.conf to add and modify the necessary parameters vim/etc/rsyslog.conf (in the global configuration segment log can specify up to two)

Open log to listen on TCP and UDP ports are turned on

local2.* define Haproxy logging location, service rsyslog Restart restart log service

Skip the Defaults configuration section to configure a simple load balancer server

Frontend refers to the front end of the agent, Main is the name *:80 all the addresses are listening on port 80, Default_backend: For frontend indicates the default backend used, use Use_backend: Indicate which backend to use

Bind can be used to specify listening for multiple ports

Backend refers to the back end of the agent, called Webservers

server specifies that the backend server web1 the IP address of the server after the specified name, check health detection unit is milliseconds by default of 2 seconds, weight weight defaults to 1, and backup means that other servers are unavailable when this server is enabled

Balance: Indicates the scheduling algorithm;
Dynamic: Weights can be dynamically adjusted
Static: Adjustment weights do not take effect in real time

Roundrobin: Polling, dynamic algorithm, support for up to 4,128 connections per back-end host

STATIC-RR: Polling, static algorithm, unlimited number of supported per backend host

Leastconn: Scheduling based on the number of loads on the backend host, only for long-connected sessions; dynamic

Source: Hash The client source address and send it to the matching server by dividing the weight of the backend server, so that the same IP address will always be sent to the same server, the default is static

URI: Hash uri This algorithm is commonly used by a proxy cache or an anti-virus agent to increase the cache hit ratio, which defaults to static

Url_param: Dispatched according to the value of the specified parameter in the URL; hash the value and divide by the total weight

HDR (<name>) : Dispatched according to the header specified in the request packet (e.g. use_agent, referer, hostname); hashes the value of the specified header

In the hash algorithm map-based is the modulus method, the static consistent is the consistent hash method, the dynamic

How to enable the Haproxy Status monitoring page is configured as follows

Listen it represents both the front end and back end, enable activation monitoring page, hide-version hidden haproxy version, auth user password Authentication if TRUE only Admin user authentication is successful to open the page

Haproxy implements another function: Session sticky based on browser cookie

Added these instructions: Cookie ServerID Insert (inserts ServerID in response message) cookie WEBSRV1 When the response message is Web1 sent back to Haproxy, Haproxy when the response header is rebuilt when the cookie header is inserted into the SERVERID=WEBSRV1, when the client requests again, Haproxy will dispatch the request to the same server again based on the ServerID just inserted in the header

Describes the parameters of the defaults configuration segment, the parameters in the defaults if the Frotend and backend segments are not defined by default is the parameter with the defaults segment

Mode defines how the Haproxy works in HTTP | TCP Log Global indicates that the log uses the logging method defined in the full segment

Httplog rich logging format, Dontlognull does not log health detection logs

Forwardfor If-none execpt X.x.x.x/mask allows you to add x-forwarded-for headers in the request header of the backend server except which network segments to exclude, If-none Only in x-forwarded-for this header does not exist when added, if you do not specify If-none then back to overwrite the original x-forwarded-for, the agent if there is a multilevel this if-none parameter must be, This is done only for the backend server to record the real client IP address

Redispatch whether the session is allowed to be reassigned to a healthy back-end server (when a session with a backend server fails) Redispatch means allow Http-server-close Allow the Haproxy side to actively disconnect the client (if the client establishes a server connection but does not initiate a request)

3 indicates that 3 times the connection to the back-end server failed to determine that the server is not available queue timeout for queue setting request Http-request HTTP Request Timeout Length http-keep-alive Specifies the persistent connection timeout for clients and Haproxy

Not to be continued

Haproxy Detailed study Notes

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.