Haproxy build Web Cluster overview

Bowen directory
a, Haproxy Overview
1, HTTP request
2, load balancing commonly used scheduling algorithm
3, common Web cluster scheduler
two, Haproxy configuration items introduced
1, global configuration items typically have the following configuration parameters:
2, Defaults configuration items to configure the default parameters , it will generally be inherited application components, if not specifically stated in the application component, you will install the default configuration parameters:
3, the listen general configuration item configuration application module parameters:
three, Haproxy the parameter optimization

A, Haproxy Overview

Haproxy is currently more popular cluster scheduling tool, there are a lot of similar cluster scheduling tools, such as LVS and Nginx. In comparison, LVS best performance, but to build relatively complex; Nginx the upstream module supports clustering capabilities, but the cluster node health check function is not strong, the performance is not good Haproxy. Haproxy official websitehttp://www.haproxy.org/

1, HTTP requests

The protocol used to access the site through the URL is HTTP protocol, commonly referred to such requests HTTP request. HTTP GET request is divided into ways and POST method.
When visit a URL using the browser URL will be returned in accordance with the request status code, generally a normal status code 2 XX, 3 XX (eg 200,301), if the abnormal returns 4 XX, 5 XX (such as 400, 500 ). For example: access http://www.test.com/a.php?ld=123, is a GET request, if access to normal, will get a 200 status code from the log server. If this request using the POST method, then passed to ld a.php of parameters is still 123, but the URL the browser will not display ld = 123 words behind, it is recommended that when the form or content type a username and password submitted use the POST method. Either way, the value of the final a.php get is the same.

2, load balancing scheduling algorithm commonly used

LVS, Haproxy, Nginx most commonly there are three scheduling algorithm, as follows:

  • RR (Round Robin): dynamically adjusting the weighted round-robin algorithm to support the weight of running and slow-start mechanism; maximum support 4095 back-end host; in the case of server processing time equal distribution of which is the smoothest and fair algorithm. The algorithm is dynamic, re-adjust on the fly for instance starts slow server weight.

  • LC (Least Connections): the minimum number of connection algorithm, a minimum number of connections to the server receives the connection priority. Recommended for long session scenario, for example LDAP, SQL, etc. protocols, the session protocol is not suitable for short. Such as HTTP. The algorithm is dynamic, re-adjust on the fly for instance starts slow server weight.

  • SH (Source Hashing): the source address hash algorithm, to hash the request source IP address; modulo method: source address hash calculated by dividing the total weight of the server, the server changes will affect the global scheduler effect; allocated according to the results. As long as the normal server, a client the same IP address is always access the same server. If the hash results vary depending on the number of available servers, then the client will be directed to a different server; the algorithm default is static, so the right to modify the server weight is invalid runtime, but the algorithm will be based on "hash-type" of changes make adjustments.
    The algorithm is generally used in a cookie can not be inserted Tcp mode. It can also be used to refuse the use of WAN session cookie client to provide the most effective adhesion; consistency hash: changes only affect local server scheduling; dynamic scheduling.

3, common Web cluster scheduler

Current common Web cluster scheduler into software and hardware, software commonly used open source LVS, Haproxy, Nginx; hardware generally use relatively large number of F5, there are a lot of people use some domestic products such as pike, the Green League and so on.

Two, Haproxy Configuration Item Description

Haproxy configuration file is usually divided into three parts:

  • global;
  • defaults;
  • the listen;
    Global global configuration, defaults to the default configuration, listen to configure the application components.

1, global configuration item usually has the following configuration parameters:

global
        log 127.0.0.1   local   <!--配置日志记录,local0为日志设备,默认存放到系统日志-->
        log 127.0.0.1   local1 notice  <!--notice为日志级别,通常有24个级别-->
        #log loghost    local0 info
        maxconn 4096          <!--最大连接数-->
        chroot /usr/share/haproxy   <!--该服务自设置的根目录,一般需将此行注释掉-->
        uid 99         <!--用户UID-->
        gid 99        <!--用户GID-->
        daemon        <!--守护进程模式-->

2, defaults configuration items to configure the default parameters, application components will generally be inherited, if not specifically stated in the application component, the default installation configuration parameters:

defaults
        log     global       <!--定义日志为global配置中的日志定义-->
        mode    http                 <!--模式为http-->
        option  httplog              <!--采用http日志格式记录日志-->
        option  dontlognull
        retries 3         <!--检查节点服务器失败次数,连续达到三次失败,则认为节点不可用-->
        redispatch             <!--当服务器负载很高时,自动结束当前队列处理比较久的连接-->
        maxconn 2000                      <!--最大连接数-->
        contimeout      5000              <!--连接超时时间-->
        clitimeout      50000             <!--客户端超时时间-->
        srvtimeout      50000             <!--服务器超时时间-->

3, listen CI general application module configuration parameters:

listen  appli4-backup 0.0.0.0:10004   <!--定义一个名为appli4-backup的应用-->
                option  httpchk /index.html   <!--检查服务器的index.html文件-->
                option  persist   <!--强制将请求发送到已经down掉的服务器,一般禁用此选项-->
                balance roundrobin  <!--负载均衡调度算法使用轮询算法-->
            server  inst1 192.168.114.56:80 check inter 2000 fall 3     <!--定义在线节点-->
         server  inst2 192.168.114.56:81 check inter 2000 fall 3 backup <!--定义备份节点-->
<!--注意:在以上定义备份节点的参数中,
“check inter 2000”表示haproxy服务器和节点之间的一个心跳率,
“fall 3”表示连续三次检测不到心跳频率则认为该节点失效。
节点配置后带有“ backup”表示该节点只是个备份节点,
只有主节点失效该节点才会上。去除backup,表示为主节点,
和其他主节点共同提供服务-->

Three, Haproxy the parameter optimization

About Haproxy parameter optimization, the following are examples of several key parameters, and optimize the production environment of each parameter recommended explained:
Haproxy build Web Cluster overview

------ This concludes the article, thanks for reading ------

Guess you like

Origin blog.51cto.com/14156658/2458216