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.
Topology diagram:
The first step:, here we use three virtual machines to do the test, the front-end of a haproxy do scheduling, the back end of two httpd servers to provide Web services, in the static and dynamic separation of the front-end haproxy to determine the dynamics and static content separately dispatched to which server;
Add two Nic in Haproxy NODE5 to define the newly added NIC in Vmnet2
Two back-end static and dynamic nodes are also set to Vmnet2
The second step: Install httpd, PHP and Haproxy, here we directly with Yum to install, after installation to 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, NODE5 Haproxy hosts on this virtual machine, Node1 and Node2 are different virtual hosts that provide a Web server to the two backend
[[email protected] ~]# yum install-y haproxy[[email protected] ~]# ifconfig eth1 192.168.1.10/24 up[[email& Nbsp;protected] ~]# ifconfigeth0 Link encap:ethernet HWaddr 00:0c:29:ba:4e:78 inet addr:192.168.8.43 Bca st:192.168.8.255 mask:255.255.255.0 inet6 addr:fe80::20c:29ff:feba:4e78/64 scope:link up BROADCAST RUN NING multicast mtu:1500 metric:1 RX packets:1418 errors:0 dropped:0 overruns:0 frame:0 TX packets:185 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:103198 (10 0.7 KiB) TX bytes:19819 (19.3 KiB) eth1 Link encap:ethernet HWaddr 00:0c:29:ba:4e:82 inet addr:192.168.1. Ten bcast:192.168.1.255 mask:255.255.255.0 inet6 addr:fe80::20c:29ff:feba:4e82/64 scope:link up BROADC AST RUNNING multicast mtu:1500 metric:1 RX packets:63 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:3780 (3.6 KiB) TX bytes:468 (468.0 b) Lo Link encap:local Loopback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr::: 1/128 scope:host up Loopback Runni NG mtu:16436 metric:1 RX packets:12 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1244 (1.2 KiB) TX bytes:1244 (1.2 KiB)
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;
192.168.1.20:
# yum install-y php httpd# ifconfig eth0 192.168.1.20/24 up# route add defaulte GW 192.168.1.10 # Gateway points haproxy to eth1 host # ping 192.168.1.10 # Ping the Haproxy node to see if the ping Pass # vim/var/www/html/index.html
192.168.1.30:
# yum install-y php httpd# ifconfig eth0 192.168.1.30/24 up# route add defaulte GW 192.168.1.10 # Gateway points haproxy to eth1 host # ping 192.168.1.10 # Ping the Haproxy node to see if the ping Pass # vim/var/www/html/index.html
Test whether the page is properly accessed
[Email protected] ~]# curl-i http://192.168.1.20HTTP/1.1 Okdate:mon, May 12:00:53 gmtserver:apache/2.2.15 (CentOS) x-powered-by:php/5.3.3connection:closecontent-type:text/html; Charset=utf-8[[email protected] ~]# curl-i http://192.168.1.30HTTP/1.1 Okdate:fri, APR 02:55:57 gmtserver:a pache/2.2.15 (CentOS) x-powered-by:php/5.3.3connection:closecontent-type:text/html; Charset=utf-8
The third step: Configure the relevant configuration information of Haproxy;########## # # # # # # # # # # # # # # # # # # ###################### #frontend Web *:80 # * indicates that Haproxy listens to all addresses, listens on a port of 80 # defines access control, represents a URL with a. css. js. html . PHP end of the separately dispatched to which server to access the 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 that the url_static is dispatched to this server if the condition is met use_backend static if url_static Default_backend dynamicbackend Static # defines a server Node1 192.168.1.20:80 check inter on servers that call the back-end of a page on the site E 2 Fall 2 maxconn 5000backend Dynamic # Defines a server that calls the back-end Dynamics page on servers Node2 192.168.1.30:80 check Inter rise 2 Fall 2 Maxconn Listen Statspage # define the interface of the monitoring management interface bind *:8888 # define the access page Port stats Enable # Enables the Admin interface stats Hide-versi On # hidden version Stats uri/admin?stats # access path stats auth Admin:centos # Access requires authentication login Stats Admin If TRUE # if login The online server can be managed successfully
To access the Administration page:
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.Using Haproxy+apache to realize dynamic and static separation of Web services in CentOS 6.5 environment