Haproxy practice of HTTP Layer load balancing

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.gz   
CD haproxy-1.4.9  
Make Target=linux26 Prefix=/haproxy  
Make install Prefix=/haproxy Create the log directory mkdir/home/haproxy/logs/create the profile directory mkdir/etc/haproxy/

Prefix=/haproxy: Install directory prefix

The launcher will be installed in the/haproxy/sbin/haproxy

Configuration

Vim/etc/haproxy/haproxy.cfg

Global log 127.0.0.1 local3 #log 127.0.0.1 local1 notice #log loghost local0 info ma         Xconn 4096 #chroot/usr/local/haproxy #chroot/home/haproxy UID 502 GID 502 Daemon Nbproc 1 pidfile/home/haproxy/logs/haproxy.pid #debug #quiet defaults log glob Al mode HTTP option httplog option dontlognull option forwardfor option Redi Spatch log 127.0.0.1 local3 retries 3 maxconn 32000 balance roundrobin stats ur I/haproxy-stats contimeout clitimeout 50000 srvtimeout 50000 Liste        n web_proxy *:80 appsession jsessionid len #插入cookie的方式 timeout 3h cookie SRV Insert Indirect nocache #模式有http TCP Health Mode HTTP stats enable stats hide-version #查看状态 stats Uri/hapro Xy-stats Stats refResh 10s monitor-uri/haproxy_test #负载均衡方案: Wheel tune balance roundrobin option Httpclose #后端可以获取客户         End of the real IP option forwardfor #健康检查 option httpchk head/login http/1.0 #option httpchk get/ping.jsp #后端真实服务 Server WebA 192.168.1.226:8081 cookie A Check server WebB 192.168.1.246:8888 cookie B che Ck

Note The configuration check address here

Option Httpchk Head/login http/1.0

Start

/haproxy/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

Haproxy practice of HTTP Layer load balancing

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.