About haproxy
Provides high availability, Server Load balancer, and proxy Based on TCP and HTTP applications, and supports Virtual Hosts. It is a free, fast, and reliable solution. Haproxy is especially suitable for websites with extremely high loads, which usually require session persistence or layer-7 processing. Haproxy runs on the current hardware and supports tens of thousands of concurrent connections. In addition, its running mode enables it to be easily and securely integrated into your current architecture, while protecting your web servers from being exposed to the network.
Haproxy Installation
Source code compilation and installation methods
Tar zxvf haproxy-1.4.8.tar.gz
CD haproxy-1.4.8
Make target = linux26 prefix =/usr/local/haproxy
Make install prefix =/usr/local/haproxy
If it is a centos liunx server, you can directly use Yum to install
Yum install haproxy
Haproxy Configuration
After haproxy is installed, modify the configuration file to manage the proxy
VI/etc/haproxy. cfg
global log 127.0.0.1 local3 notice ulimit-n 40960 maxconn 10240 user haproxy group haproxy nbproc 4 daemon quiet defaults log global mode http option tcplog listen my_80 bind 0.0.0.0:80 balance roundrobin mode tcp option tcpka server test 192.168.1.2:80 listen my_82 bind 0.0.0.0:82 balance roundrobin mode tcp option tcpka server test 192.168.1.2:80
The above configuration file means to proxy port 80 and port 82 of the Local Machine to port 80 of the 192.168.1.2 server,
Access the port of machine B by accessing the port of machine.
Haproxy precautions
Some problems have not been explained. When the number of connections of the haproxy proxy exceeds 10000, the efficiency is obviously low and it is difficult to create a connection,
Therefore, in general large concurrent requests, try to use LVS or your own request distributor. haproxy can only be applied to small-scale requests and toy applications,
Its advantage is that it is simple and convenient to respond to the stress of applications with small requests and non-persistent connections.