Evolution of large-scale Web Site system Architecture (iv) The Haproxy practice of HTTP Layer load balancing (i)

Source: Internet
Author: User
Tags haproxy

Scheme

In the previous article, we discussed the theoretical knowledge of load balancing, and this article I intend to talk about practical methods and problems encountered in practice

Scenario: Haproxy HTTP Layer Load Balancing

Install a Haproxy service, two Web services

Haproxy:192.168.1.227:80

Web1 Http://192.168.1.226:8081/login

WEB2 Http://192.168.1.246:8888/login

The Web service is prepared for itself, and the article does not say

Load balancing algorithm for polling scheduling

Session retention implemented as cookie recognition, insert cookie

Advantages:

1 Simple configuration

2 Session hold function available

3 Good performance

Installation and Configuration

Installation

tar -zxvf haproxy-1.49. Tar
CD Haproxy-1.4. 9
 Make Target=linux26 prefix=/
 Make Install prefix=/mkdir /home/haproxy/logs/

Configuration

Global Log127.0.0.1Local3 #log127.0.0.1local1 Notice #log loghost local0InfoMaxconn4096       #chroot/usr/local/Haproxy #chroot/home/haproxy UID502GID502Daemon Nbproc1Pidfile/home/haproxy/logs/haproxy.pid #debug #quiet Defaults log global mode HTTP option htt Plog option dontlognull option forwardfor option Redispatch log127.0.0.1Local3 Retries3Maxconn32000balance Roundrobin stats URI/haproxy-Stats Contimeout theClitimeout50000Srvtimeout50000Listen Web_proxy*: theappsession Jsessionid Len theTimeout 3h #插入cookie的方式 cookie SRV Insert indirect nocache #模式有http TCP Health mode HTTP Stats Enable stats Hide-version #查看状态 stats URI/haproxy-Stats stats Refresh 10s monitor-uri/haproxy_test #负载均衡方案: rotation balance roundrobin option httpclose #后端可以获取客户端的真实ip option FORW Ardfor #健康检查 option Httpchk HEAD/login http/1.0#option httpchk GET/Ping. JSP #后端真实服务 Server WebA192.168.1.226:8081cookie A Check server WebB192.168.1.246:8888Cookie B Check

Note The configuration check address here

Option Httpchk Head/login http/1.0

Start

/usr/local/sbin/haproxy-f/etc/haproxy/haproxy.cfg

View process

Ps-ef|grep Haproxy

Close process

Kill–9 PID

View the Monitoring page

Http://192.168.1.227/haproxy-stats

Such as: Note that the Status column shows 200, if not the Web server does not start, or the Health Check link is not accessible

Test

Then open a different browser to simulate user access

http://192.168.1.227/login/

'll see

Proof that the request was distributed to a different Web server

View Cookies

The cookie was added to the Srv=a

Process of Session Retention

1. On the first request of the client, the Web server Set-cookie and responds to Haproxy when haproxy to the Web service side

2.haproxy inserts srv=a after the cookie and responds to the client

3. The client second request, after Haproxy, haproxy the SRV suffix, then requests the server

Summarize

The problem solved by the program

1. Load balancing and address a single point of failure for Web services

2. Session hold

Disadvantages of existence

1.web Server session Save a single point of failure, that is, one of the Web server downtime, stored in the above session will be lost

2. There is a single point of failure on the Load Balancer server

The next article will discuss how to solve the above 2 disadvantages

Previous article Evolution of the system architecture of large Web sites (iii) How to improve the high availability and high performance of Web sites

Directory large Web Site system Architecture Evolution Directory

Evolution of large-scale Web Site system Architecture (iv) The Haproxy practice of HTTP Layer load balancing (i)

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.