HAProxy provides high availability, Server Load balancer, and TCP and HTTP application-based proxy. It supports Virtual Hosts and is a free, fast, and reliable solution.
HAProxy provides high availability, Server Load balancer, and TCP and HTTP application-based proxy. It supports Virtual Hosts and 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 implements an event-driven, single-process model that supports a large number of concurrent connections. Multi-process or multi-thread models are limited by memory, system schedulers, and ubiquitous lock restrictions, and are rarely able to process thousands of concurrent connections. Because the event-driven model implements all these tasks on a User-Space with better resource and time management, there is no such problem. The disadvantage of this model is that in multi-core systems, these programs are generally less scalable. This is why they must be optimized to make every CPU time slice (Cycle) do more work.
-- From Baidu encyclopedia
Implementation process diagram:
Step 1: Install httpd, php, and haproxy. Here we can install httpd directly using yum. Here we use three virtual machines for testing and one front-end haproxy for scheduling, the two backend httpd servers provide web Services, and the front-end haproxy is used to determine which server the dynamic and static content are scheduled to when the dynamic and static content is separated;
[Root @ node0 ~] # Yum-y install httpd php haproxy Step 2: After the installation, configure related network devices for the three virtual machines and provide related test pages. Select the same communication channel on the eth1 Nic, node0 is the haproxy host on this virtual machine. node1 and node2 are two different backend web server virtual hosts;
[Root @ node0 ~] # Ifconfig eth1 192.168.27.10/24 up # configure an IP address for eth1
[Root @ node0 ~] # Ifconfig
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: B2: AD: BA
Inet addr: 172.16.27.88Bcast: 172.16.255.255 Mask: 255.255.255.0.0
Inet6 addr: fe80: 20c: 29ff: feb2: adba/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 11122303 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1193136 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 697850934 (665.5 MiB) TX bytes: 74549101 (71.0 MiB)
Eth1 Link encap: Ethernet HWaddr 00: 0C: 29: B2: AD: C4
Inet addr: 192.168.27.10Bcast: 192.168.27.255 Mask: 255.255.255.0
Inet6 addr: fe80: 20c: 29ff: feb2: adc4/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 6 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 0 (0.0 B) TX bytes: 468 (468.0 B)
[Root @ node0 ~] #Configure related configurations on node1 and node2, select the same communication channel of VMnet2 and eth1 on haproxy on the virtual machine, and then configure the IP address and default gateway interface, then provide different pages for testing;
[Root @ node1 ~] # Ifconfig eth0 192.168.27.18/24 up
[Root @ node1 ~] # Route add defaulte gw 192.168.27.18 # The Gateway points to the eth1 address of the haproxy host
[Root @ node1 ~] # Ping 192.168.27.10 # ping the haproxy node to check whether the haproxy node is successfully pinged.
[Root @ node1 ~] # Vim/var/www/html/index.html
<H1> node1.tanxw.com
[Root @ node1 ~] # Service httpd start # After configuration, start the web service, access the test, and change the test connection to the Bridge Mode.
[Root @ node2 ~] # Ifconfig eth0 192.168.27.19/24 up
[Root @ node2 ~] # Route add defaulte gw 192.168.27.18 # The Gateway points to the eth1 address of the haproxy host
[Root @ node2 ~] # Ping 192.168.27.10 # ping the haproxy node to check whether the haproxy node is successfully pinged.
[Root @ node2 ~] # Vim/var/www/html/index. php
<H1> node2.tanxw.com
<? Php
Phpinfo ();
?>
[Root @ node2 ~] # Service httpd start # After configuration, start the web service, access the test, and change the test connection to the Bridge Mode.
Step 3: Configure relevant configuration information of haproxy;
############# Use the default configuration above ################## #####
Frontend web *: 80 # * indicates that haproxy listens to all addresses and the listening port is 80.
# Define which server to access by urlending with .css. js. html. php
Acl url_static path_end-I. css. js. html
Acl url_dynamic path_end-I. php
# Usr_backend indicates that the backend service is used. if it indicates that the url_static condition is met, it is scheduled to this server.
Use_backend static if url_static
Default_backend dynamic
Backend static # defines the server on which the backend static page is called
Server node1 192.168.27.18: 80 check inter 3000 rise 2 fall 2 maxconn 5000
Backend dynamic # defines the server on which the backend dynamic page is called
Server node2 192.168.27.19: 80 check inter 3000 rise 2 fall 2 maxconn 5000
Listen statspage # interface for defining monitoring management interfaces
Bind *: 8888 # define the access page Port
Stats enable # enable management interface
Stats hide-version # hide version
Stats uri/admin? Stats # access path
Stats auth xiao: linux # login verification required during access
Stats admin if TRUE # You can manage online servers if logon is successful.Step 4: log on to the configured management interface:
Step 5: After configuring the relevant configuration, you can test it,
Finally, let's perform a stress test on the requests on these two pages:
Summary:
HAProxy is a lightweight Server Load balancer server. It is especially suitable for websites with extremely large loads that 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.
This article from the "warm boiled frog" blog, please be sure to keep this source http://tanxw.blog.51cto.com/4309543/1407694