HAProxy provides high availability, load balancing, and proxies based on TCP and HTTP applications, supporting virtual hosting, which is a free, fast, and reliable solution.
Haproxy provides high availability, load balancing, and proxies based on TCP and HTTP applications, supporting virtual hosting, which is a free, fast, and reliable solution. Haproxy is especially useful for Web sites that are heavily loaded, and often require session-hold or seven-tier processing. The haproxy runs on the current hardware and can support tens of thousands of concurrent connections. and its operating mode makes it easy and safe to integrate into your current architecture, while protecting your Web server from being exposed to the web.
Haproxy implements an event-driven, single-process model that supports very large number of concurrent connections. A multi-process or multithreaded model is rarely capable of handling thousands of concurrent connections because of memory limitations, System scheduler restrictions, and ubiquitous lock limits. The event-driven model does not have these problems because it implements all of these tasks on the client side (User-space) with better resource and time management. The disadvantage of this model is that, on multicore systems, these programs often have poor extensibility. That's why they have to be optimized so that each CPU time slice (Cycle) does more work.
--from Baidu Encyclopedia
Implementation process diagram:
The first step: install httpd, PHP and Haproxy, here we directly with Yum to install, here we use three virtual machines to do the test, the front-end of a haproxy to do scheduling, the back end of two httpd servers to provide Web services, When doing static and dynamic separation, the front-end haproxy to determine which servers are dynamically and statically dispatched to each other;
[[email protected] ~]# yum-y install httpd php haproxy |
The second step: after the installation of the three virtual configuration of the relevant network equipment and provide relevant test page, etc., in the eth1 this net card to choose the same communication channel, NODE0 this virtual machine haproxy host, Node1 and Node2 are different virtual hosts that provide Web servers for both back ends;
[[email protected] ~]# ifconfig eth1 192.168.27.10/24 Up # Configure IP address for eth1 [Email protected] ~]# ifconfig Eth0 Link encap:ethernet HWaddr 00:0c:29:b2:ad:ba inet addr:172.16.27.88 bcast:172.16.255.255 mask: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 txqueuelen: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.10 bcast: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 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:468 (468.0 b) [Email protected] ~]# |
Set up the relevant configuration on Node1 and Node2, select the same communication channel of eth1 on the VMnet2 and Haproxy on the virtual machine, configure the IP address and default gateway interface, and then provide different pages for testing;
[[email protected] ~]# I Fconfig eth0 192.168.27.18/24 up [[email protected] ~]# route add defaulte GW 192.168.27.18 # The gateway points to the eth1 address of the Haproxy host [[email protected] ~]# ping 192.168.27.10 # Ping the Haproxy node to see if Ping is [[email protected] ~]# vim/var/www/html/index.html [[email protected] ~]# service httpd start # is configured to start the Web service and then access the test, Test connection changed to bridging mode |
[Email protected] ~]# ifconfig eth0 192.168.27.19/24 up [[email protected] ~]# route add defaulte GW 192.168.27.18 # Gateway to Haproxy address of eth1 host [[email protected] ~]# Ping 192.168.27.10 # Ping Haproxy node to see if ping [Email protected] ~]# vim/var/www/html/index.php <?php Phpinfo (); ?> [[Email protected] ~]# Service httpd Start # Configure the Web service and then access the test, the test connection is changed to bridging mode |
The third step: Configure the relevant configuration information of Haproxy;
Using the default configuration above ############## is possible #######################
Frontend Web *:80 # * indicates that Haproxy listens to all addresses and listens on a port of 80 # defines an access control that represents a URL with a. css. js. html. PHP end of the separately dispatched to which server to access ACL url_static path_end-i. css. js. html ACL url_dynamic path_end-i. php
# Usr_backend indicates the use of the backend service, if it means to dispatch to this server if the condition of url_static is met Use_backend Static If Url_static Default_backend Dynamic
Backend Static # defines a call to the back-end on a server that is still a page Server Node1 192.168.27.18:80 check Inter rise 2 Fall 2 Maxconn 5000 Backend Dynamic # Defines a server that calls the back-end Dynamics page Server Node2 192.168.27.19:80 check Inter rise 2 Fall 2 Maxconn 5000 Listen Statspage # Defines the interface of the Monitoring management interface Bind *:8888 # Defines the access page port Stats Enable admin interface Stats Hide-version # hidden version Stats Uri/admin?stats # Access Path Stats Auth Xiao:linux # access requires authentication login Stats admin If TRUE # Manage online servers if you log in successfully |
Fourth Step : Login to our configured management interface:
Fifth Step: Configure the relevant configuration so that you can test it,
Finally, we will do the two pages of the request for a stress test to see:
Summarize:
The Haproxy is a lightweight, load-balanced server, especially for those web sites that are heavily loaded, and often require session-hold or seven-tier processing. The haproxy runs on the current hardware and can support tens of thousands of concurrent connections. and its operating mode makes it easy and safe to integrate into your current architecture, while protecting your Web server from being exposed to the web.
This article is from the "boiled frog with boiling water" blog, please make sure to keep this source http://tanxw.blog.51cto.com/4309543/1407694