HAProxy is a proxy software that provides high availability, server load balancer, and TCP and HTTP applications, HAProxy is a completely free proxy solution that provides TCP and HTTP applications quickly and reliably with HAProxy. HAProxy is applicable to websites with large loads. these sites usually need session persistence or layer-7 processing. HAProxy supports tens of thousands of concurrent connections.
HAProxy is a proxy software that provides high availability, server load balancer, and TCP and HTTP applications, HAProxy is a completely free proxy solution that provides TCP and HTTP applications quickly and reliably with HAProxy. HAProxy is applicable to websites with large loads. these sites usually need session persistence or layer-7 processing. HAProxy supports tens of thousands of concurrent connections, and the HAProxy running mode enables it to be easily and securely integrated into the architecture, while protecting web servers from being exposed to the network.
It is powerful in layer-7 load balancing (supports cookie track, header rewrite, etc.), supports dual-host hot backup, supports virtual hosts, has a very good server health check function, when the back-end server of the proxy fails, HAProxy will automatically remove the server and automatically add the server after the fault is restored. It also provides an intuitive monitoring page, the service cluster running status can be clearly monitored in real time.
In the new version 1.3, frontend and backend configuration segments are introduced. frontend performs rule matching based on any HTTP request header content, and then directs the request to the relevant backend, using ACL, you can implement functions similar to F5's irules. Very powerful. Currently, haproxy supports the following five load balancing algorithms. It also supports adjusting the load ratio through weight and enabling connection persistence through cookies.
1. Round Robin roundrobin
2. least connections Leastconn
3. based on the source IP address source
4. according to the URI uri
5. based on the URL parameter url_param (perform lb after hush ing based on the data in the request string. for example, if a userid is always on a server, the policy is static)
Deploy haproxy
1. Installation
# Wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.20.tar.gz
# Tar zcvf haproxy-1.4.20.tar.gz
# Cd haproxy-1.4.20
# Make TARGET = linux26 ARCH = x86_64
# Make install PREFIX =/usr/local/haproxy
2. configuration
Mkdir/usr/local/haproxy/conf
Vi/usr/local/haproxy/conf/haproxy. cfg
Global
Log 127.0.0.1 local0
Maxconn 65535 # maximum number of connections
Chroot/usr/local/haproxy
Uid 99
Gid 99
Daemon
# Debug
# Quiet
Nbproc 1 # number of concurrent processes of server load balancer
Pidfile/var/run/haproxy. pid
ULTS
Log global
Mode http # working mode. Currently, three (tcp/http/health) modes are supported)
Option httplog # log category
Option dontlognull
Option redispatch # When the server corresponding to the serverid goes down, it is forcibly directed to another healthy server.
Log 127.0.0.1 local0
Retries 3 # Number of retries
Maxconn 32000
Stats enable
Stats uri/haproxy-stats
Stats realm Haproxy \ Statistics # Message
Stats auth admin: admin # User authentication/user name and password
Stats hide-version # hide version information
Stats refresh 10 s # refresh time
Contimeout 5000 # timeout
Clitimeout 50000
Srvtimeout 50000
Listen appserver *: 80
Hash-type consistent
Balance uri len 100
Option httpclose # enable passive http connection closure
Option httpchk HEAD/do_not_delete/noc.gif HTTP/1.0 # health check
Server img_web_01 192.168.11.51: 80 cookie 10 weight 3 check inter 2000 rise 2 fall 3
Server img_web_02 192.168.11.52: 80 cookie 20 weight 3 check inter 2000 rise 2 fall 3
Server img_web_03 192.168.11.53: 80 cookie 30 weight 3 check inter 2000 rise 2 fall 3
Haproxy startup
/Usr/local/haproxy/sbin/haproxy? F/usr/local/haproxy/conf/haproxy. cfg
Restart service
/Usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/conf/haproxy. cfg-st 'cat/var/run/haproxy. Pi'
View on the Web page