Haproxy Deploying a Web site lb cluster

Source: Internet
Author: User
Tags php website haproxy nginx load balancing

Introduction: The difference between LVS and Haproxy

Lvs:

1, strong anti-load capacity, is the work in the Network 4 layer on the distribution only, no flow generation;

2, no flow, to ensure that the performance of the Equalizer IO will not receive the impact of large traffic;

3, the application of a wide range, because LVS work in the 4 layer, so it can almost all applications to do load balancing

4, the work is stable, because of its own resistance to load capacity is very strong, self has a complete dual-machine hot-Standby program,

such as lvs+keepalived, but we in the project implementation of the most used is still lvs/dr+keepalived.

Haproxy:

1, Haproxy is also supporting the virtual host

Haproxy similar to LVS, itself is just a load balancer software, based on seven layers;

2, simply from the efficiency of the haproxy will be better than nginx load balancing speed,

In the concurrent processing is also superior to nginx;

3, Haproxy support the TCP protocol load-balanced forwarding,

MySQL reads can be load balanced, and backend MySQL nodes are detected and load balanced


Preparatory work:

1. Prepare four hosts: IP address planning is

4.49,4.50 (Haproxy), 4.51 (web), 4.52 (web)

2, install Haproxy Software on 4.50, on 4.51 and 4.52

Installing HTTPD Software


I. Common LB cluster

1, modify the configuration file: Vim/etc/haproxy/haproxy.cfg

Delete all content below 60 lines, add the following content

Stats Uri/admin

Listen Lbweb 0.0.0.0:80

ServerID Cookie Rewrite

Balance Roundrobin

web51 192.168.4.51:80 Cookie App51 check Inter 2 rise 5

Server web52 192.168.4.52:80 Cookie app52 check Inter 2 rise 5

2, can go to Page view Health: Http://192.168.4.50/admin

3. Test: Stop one of the Web servers and go back to the background to view the number of session sessions in the background


II. Division of Business-differentiated lb clusters

1. Test with four servers

4.51 and 4.52 do HTML load, 4.53 and 4.54 do PHP load

2, above 4.51 and 4.52 have done, now put 4.53 and 4.54 do PHP website

3. Modify configuration file: Vim/etc/haproxy/haproxy.cfg

Stats Uri/admin

#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

Frontend weblb 192.168.4.100:80

# ACL url_static path_beg-i/static/images/javascript/stylesheets

path_html ACL path_end-i. html

path_php ACL path_end-i. php

67

Use_backend HTMLG If path_html

Use_backend PHPG If path_php

Default_backend HTMLG

71

#---------------------------------------------------------------------

# Static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------

#backend Static

# balance Roundrobin

# # server static 127.0.0.1:4331 check

78

#---------------------------------------------------------------------

# round robin balancing between the various backends

Bayi #---------------------------------------------------------------------

Backend HTMLG

Balance Roundrobin

Server app101 192.168.4.101:80 Check

app102 192.168.4.102:80 Check

86

Backend PHPG

Balance Roundrobin

192.168.4.103:80 Check for app103 server

Server app104 192.168.4.104:80 Check


4, save the configuration, restart the service, test:

Put test.html and test.php Web files on four servers, respectively.

Test separately on the client side to produce the expected results

























Haproxy Deploying a Web site lb cluster

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.