Tens high concurrency load balancing software haproxy

Source: Internet
Author: User
Tags haproxy rsyslog

First, HAProxy

Hardware-based load balancing devices: F5,BIG-IP, etc.

Software-based load balancing products: Haproxy,lvs,nginx, etc.

In the software load balancing product, it is divided into system-based soft load implementation and soft load implementation based on third-party software, and LVs is a kind of soft load based on system implementation. HA Proxy is a soft load balancer based on third-party application

1.haproxy Introduction

Haproxy is an open-source, high-performance load balancing software based on TCP layer fourth and HTTP seventh application

Advantages: Very good reliability and stability

Up to 40000-50000 concurrent connections can be maintained at the same time. The maximum number of requests processed per unit of time is 20000. Maximum data processing capacity up to 10GBPS

Supports more than 8 load-balancing algorithms while also supporting session retention

Supports the virtual Host feature.

Support for connection rejection, full transparent proxy and other functions

Haproxy has a powerful server status monitoring page

Haproxy has strong ACL support

In terms of business systems. Haproxy is very useful for web systems that are extremely large and require persistent connectivity or four-and seven-layer processing, such as e-commerce , and haproxy can also be used in MySQL Load balancing of databases (read operations)



2. Difference between four-and seven-layer load balancing

A four-tier load balancer, also known as a four-layer switch, is primarily based on ip+ ports that are implemented by analyzing traffic on the IP layer and TCP/UDP layer

TCP Application Example: When the load balancer receives the first request from a SYN, it chooses an optimal back-end server through the set load balancing algorithm, modifies the destination IP in the message to the back-end server IP, and forwards it directly to the server. The load Balancer acts as a router in this process

The seven-layer load balancer, also known as the 7-layer switch, is located in the ISO application layer and supports a variety of application protocols, common HTTP,FTP,SMTP, etc. The seven-tier load balancer can select back-end servers based on the content of the message and then in conjunction with the load balancing algorithm. Therefore also known as the "content switch". A seven-tier load balancer is similar to a proxy server in this case.

The similarities and differences between 3.haproxy and LVS

Both are software load-balanced products. But LVs is system-based, and Haproxy is based on third-party applications

LVS is based on the fourth layer of IP load technology. Haproxy is a comprehensive load balancing solution for TCP and HTTP applications based on layers fourth and seventh

LVS works on the fourth level of the ISO model with a single state monitoring function. Haproxy monitoring function, can support port, URL, script and many other detection methods

Haproxy processing LVS with performance less than four-layer load Balancing mode

Choosing that as a load balancer requires a real-world decision

4.haproxy basic configuration and application examples

Quick Install proxy cluster software

tar zxxvf haproxy-1.4.24.tar.gz

CD haproxy-1.4.24

Make Target=linux26 Prefix=/usr/local/haproxxy

Make install Prefix=/usr/local/haproxy

Mkdir/usr/local/haproxy/conf #创建配置文件目录

CP examples/haproxy.cfg/usr/local/haproxy/conf/

Haproxy Basic Configuration file

The whole is divided into five parts: global (used to set the overall configuration parameters)

Defaults section (configuration portion of the default parameter)

Frontend (front-end virtual node for setting user requests)

Backend (used to set the configuration of the cluster backend service cluster, i.e. to add a set of real servers to handle the previous request)

Listen (combination of frontend and backend)


Global

log 127.0.0.1 local1 notice

Maxconn 4096

Chroot/usr/share/haproxy

UID 99

GID 99

Daemon

Nbproc 1

Pidfile/usr/local/haproxy/logs/haproxy.pid

Local1 is a log device, notice is a log level,

Daemon set Haproxy to run in the background

Nbproc set the number of processes that can be created when Haproxy starts

Maxconn sets the maximum number of concurrent connections accepted by the Haproxy process, which is equivalent to "ulimit-n"

Defaults

Mode HTTP

Retries 3

Timeout Connect 10s #连接到一台服务器的最长等待时间

Timeout Client 20s #连接客户端发送数据最长等待时间

Timeout server 30s #服务器回应客户端发送数据最长等待时间

Timeout Check 5s #对后端服务器的检测超时时间

Mode: Sets the default operating mode of the Haproxy instance, which mode is Tcp,http,health

TCP mode: A full-duplex connection will be established between the client and the server, without any checks on the seven beginning, default to TCP mode, often used for applications such as SSL,SSH,SMTP

HTTP mode: Client requests will be analyzed in depth before being forwarded to the backend server, and all requests incompatible with the RFC format will be rejected

Retries: Setting the number of failed retries for the connected back-end server

Haproxy configuration File Details _ server application _linux commune-linux System Portal

http://www.linuxidc.com/Linux/2012-07/65350.htm

Haproxy Log Policy

Vim/etc/rsyslog.d/haproxy.conf

$ModLoad imudp

$UDPServerRun 514

local3.*/usr/local/haproxy/logs/haproxy.log

local0.*/usr/local/haproxy/logs/haproxy.log

Vim/etc/sysconfig/rsyslog

syslogd_options= "-C 2-r-M 0" #-r means accepting remote logs

Service Rsyslog Restart

Intelligent load Balancing with Haproxy ACL rules

Function: Check whether client requests are legitimate by setting ACL rules, if legitimate, rest assured. If it is not lawful, refuse.

Requests that conform to ACL rules are committed to the backend backend server cluster, which enables load balancing based on ACL rules

ACL rules are often used in the Frontend field

ACL name ACL Method-I matching path or file

ACL methods: Hdr_reg (Host), Hdr_dom (host), Hdr_beg (host), Url_sub,url_dir,path_beg,path_end, etc.

Second, the actual project

An example of Haproxy load Balancing system configuration based on virtual host

1>, architecture diagram

650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" image "border=" 0 "alt=" image "src=" http ://s3.51cto.com/wyfs02/m02/85/48/wkiom1efdowj-xytaadshplg3ki094.png "height=" 338 "/>

2>, experimental environment

System environment: CentOS6.5 haproxy-1.4.24.tar.gz

1. Configuring a virtual host with ACL rules

Environment:

Haproxy (Load Balancer Scheduler): 192.1682.10

E-Commerce Server cluster: 192.168.2.201 (web1) domain name www.hyzc.com

192.168.2.202 (web2) domain name www.hyzc.com

2. Configuring the Haproxy configuration file

# vim/usr/local/haproxy/conf/haproxy.cfg

# This config needs haproxy-1.1.28 or haproxy-1.2.1  
Global    
         log 127.0.0.1   local0 info    
        Maxconn 4096    
        chroot/usr/share/haproxy    
& nbsp;       uid    
        GID 99 & nbsp  
        daemon    
         Nbproc 1    
        pidfile/usr/local/haproxy/logs/ Haproxy.pid

Defaults
Mode http
Retries 3
Timeout Connect 10s
Timeout Client 20s
Timeout server 30s
Timeout Check 5s

Listen Admin_stats
Bind 0.0.0.0:9188
Mode http
Log 127.0.0.1 Local0 Err
Stats Refresh 30s #设置haproxy监控页面刷新时间
Stats Uri/haproxy-status #设置haproxy监控页面的url路径
Stats Realm Welcome login\ Haproxy #指定登录haproxy统计页面时, text message on Password box
Stats auth admin:admin123 #指定haproxy监控页面的用户名和密码. User name and password can be separated by colons
Stats Hide-version #用来隐藏统计页面上haproxy的版本信息
Stats admin if TRUE #可用在监控页面上手工启用或禁用后端服务器. Valid after 1.4.9 version

Frontend www
Bind *:80

Mode http
Option Httplog
Option Forwardfor #如果后端服务器需要获取客户端的真实ip and need to configure this
Log Global #表示使用全局的日志配置

ACL host_www Hdr_reg (host)-I ^ (www.hyzc.com|hyzc.com)

Use_backend server_www If host_www

Backend Server_www
Mode http

        option  redispatch       # In the environment for cookie retention  
        option  abortonclose  # Automatically ends long-processing links   &NBSP in the current queue,
        balance source  #用来定义负载均衡算法.   &NBSP
        cookie  serverid  #表示向cookie插入serverid   &NBSP,
        option  httpchk get/index.html  #表示启用http服务的状态检测功能    
                       #server用来定义多台真实的后端服务器, cannot be used for defaults and frontend    
   server  web1 192.168.2.201:80 Cookie web1 weight 6 check Inter rise 2 Fall 3    
   serve r  web2 192.168.2.202:80 Cookie web2 weight 6 check Inter rise 2 Fall 3

3. Start Haproxy

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

4. E-Commerce Server cluster configuration

echo Web1 >/var/www/html/index.html

echo web2 >/var/www/html/index.html

Service httpd Restart

Vim/etc/hosts

192.168.2.201 www.hyzc.com hyzc.com

192.168.2.202 www.hyzc.com hyzc.com

5. Testing

Test Haproxy for virtual host and load balancing capabilities

Access Web sites with www.hyzc.com and hyzc.com domains through different IP clients. Server_www backend Server Default Web page information appears in turn and no other pages appear

Testing the failover capability of the HA proxy

The httpd service of 192.168.2.291 is closed and access to the www.hyzc.com site is accessed, and the failed node is not accessed. Because when the httpd service is stopped, Haproxy detects that the node cannot return data by Httpchk mode, thereby masking the ability of this node to provide services externally

Web monitoring platform using HA Proxy

Http://192.168.2.10:9188/haproxy-status

User name: admin password: admin123

650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" image "border=" 0 "alt=" image "src=" http ://s3.51cto.com/wyfs02/m00/85/48/wkiol1efdomtmbcgaajfa4xgbly438.png "height=" 417 "/>

This article is from the "willing to share with you" blog, please be sure to keep this source http://pengjc.blog.51cto.com/9255463/1833043

Tens high concurrency load balancing software haproxy

Related Article

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.