CentOS 6.5 Haproxy+apache for Web services dynamic and static separation

Source: Internet
Author: User
Tags hosting haproxy

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:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/26/0B/wKioL1Npn2qDdiOwAAEUH5H3E2Y175.jpg "title=" Haproxy.jpg "alt=" Wkiol1npn2qddiowaaeuh5h3e2y175.jpg "/>


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;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/16/wKiom1NpycrTigk9AAFTVY806zA030.jpg "title=" 7.png " alt= "Wkiom1npycrtigk9aaftvy806za030.jpg"/>

[Email protected] ~]# ifconfig eth1 192.168.27.10/24 up# Configure IP addresses for eth1
[Email protected] ~]# 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.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)

eth1Link 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 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] ~]# ifconfig eth0 192.168.27. /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.html

[[Email protected] ~]# service httpd start # Configure the Web service and then access the test, the test connection is changed to bridging mode

[Email protected] ~]# ifconfig eth0 192.168.27. /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 the haproxy listens to all addresses and listens on a port of
# 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# define a static page that calls back end on the server
Server Node1 192.168.27. -: Check Inter rise 2 Fall 2 Maxconn 5000
Backend dynamic# define a call to the backend dynamic page on the server
Server Node2 192.168.27. +: Check Inter rise 2 Fall 2 Maxconn 5000
Listen Statspage# Interface for defining the monitoring management interface
Bind *:8888# define access page ports
Stats enable# Enable admin interface
Stats Hide-version# Hidden versions
Stats Uri/admin?stats# Access Path
Stats Auth Xiao:linux# need to verify login when accessing
Stats Admin If TRUE# If login is successful, you can manage the online server

Fourth Step : Login to our configured management interface:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/26/17/wKioL1NpyEvQG7J1AAFJFJbGr34770.jpg "title=" 1.png " alt= "Wkiol1npyevqg7j1aafjfjbgr34770.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/17/wKioL1NpyJGDqzq2AAXT8Ek41q0971.jpg "title=" 2.png " alt= "Wkiol1npyjgdqzq2aaxt8ek41q0971.jpg"/>

Fifth Step: Configure the relevant configuration so that you can test it,

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/26/17/wKioL1NpyMmRMgcTAAC7idNwGA8311.jpg "title=" 3.png " alt= "Wkiol1npymmrmgctaac7idnwga8311.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/26/16/wKiom1NpyRCSCcioAAJBUPeM-gA579.jpg "title=" 4.png " alt= "Wkiom1npyrcsccioaajbupem-ga579.jpg"/>

Finally, we will do the two pages of the request for a stress test to see:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/26/17/wKioL1NpyUSDI2rLAAVLyURyTn4797.jpg "title=" 5.png " alt= "Wkiol1npyusdi2rlaavlyurytn4797.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/17/wKioL1NpyWbjjJwLAAV5MtRD1BY046.jpg "title=" 6.png " alt= "Wkiol1npywbjjjwlaav5mtrd1by046.jpg"/>


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.