Haproxy Building a Web cluster

Source: Internet
Author: User
Tags node server haproxy rsyslog

Usage Requirements: load-balanced groups can be tocat+nginx with load Balancing clusters and LVS load balancing clusters. Compared to the three population sets, the LVS performance is the best, but the building complex, NINGX upstream module support cluster, but the cluster node fault check function is not many, performance is not comparable to haproxy.

Relative to achieve what kind of effect: for the Enterprise Server (WEB.FTP, etc.) can achieve load balance, one server down can still be on the site FTP.

Description of the knowledge point: 1. Common scheduling algorithms for load Balancing:

(1): RR (Round Robin), is the simplest and most commonly used algorithm, that is, polling scheduling.

(2): LC (LEAST conections), which is the most bar point algorithm, dynamically allocates front-end requests based on the size of the backend nodes

(3): SH (source Hashing), that is, based on the source access scheduling algorithm, for some session sessions recorded on the server side of the scene, can be based on the source of Ip,cookis and other cluster scheduling

(4): If you need to achieve haproxy high availability, you can configure the previous keepalived, the configuration method is basically the same, you need to add a haproxy to do the backup, Note that there is a need to turn on the keepalived multicast address on the firewall: 224.0.0.18 port

experimental topology:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8C/25/wKiom1hjWMDjyjgrAABFsadWUew333.png-wh_500x0-wm_3 -wmp_4-s_3576563560.png "title=" 1.PNG "alt=" Wkiom1hjwmdjyjgraabfsadwuew333.png-wh_50 "/>

The steps of the experiment:

One: Compile and install Haproxy

Environment: conditions, installation Pcre-devel Bzip2-devel two support packages

Entry directory: cd/usr/src/haproxy-1.4.14

Make Target=linux26

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/8C/22/wKioL1hjXROBezS_AAAfBYWRpPk973.png-wh_500x0-wm_3 -wmp_4-s_4174070685.png "title=" 2.PNG "alt=" Wkiol1hjxrobezs_aaafbywrppk973.png-wh_50 "/>

Haproxy Server Configuration

Build the Haproxy profile and load the sample into the/etc/haproxy directory

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/8C/22/wKioL1hjXfHAv74UAAAP9JT68eY920.png-wh_500x0-wm_3 -wmp_4-s_3189396354.png "style=" Float:none; "title=" 3.PNG "alt=" Wkiol1hjxfhav74uaaap9jt68ey920.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8C/26/wKiom1hjXfHx44uvAAAanvf9nNU324.png-wh_500x0-wm_3 -wmp_4-s_444462989.png "style=" Float:none; "title=" 4.PNG "alt=" Wkiom1hjxfhx44uvaaaanvf9nnu324.png-wh_50 "/>

Finally, modify the haproxy.cfg configuration file

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/8C/22/wKioL1hjXnSid7qRAACUXckD-gI714.png-wh_500x0-wm_3 -wmp_4-s_1588049625.png "title=" 5.PNG "alt=" Wkiol1hjxnsid7qraacuxckd-gi714.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8C/26/wKiom1hjXoGARTKRAAFNGjHfTno995.png-wh_500x0-wm_3 -wmp_4-s_526766043.png "title=" 6.PNG "alt=" Wkiom1hjxogartkraafngjhftno995.png-wh_50 "/>

Creating a self-initiated script because Haproxy represents system services

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8C/26/wKiom1hjXvPCnejyAAAdSB2yeF0827.png-wh_500x0-wm_3 -wmp_4-s_3895376846.png "title=" 7.PNG "alt=" Wkiom1hjxvpcnejyaaadsb2yef0827.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8C/22/wKioL1hjXv_wyflxAAAdzASW_L4197.png-wh_500x0-wm_3 -wmp_4-s_1766854770.png "title=" 8.PNG "alt=" Wkiol1hjxv_wyflxaaadzasw_l4197.png-wh_50 "/>

Second: Install Nginx and make a simple web page to test

Yum-y Install Pcre-devel Zlib-devel

Tar zxf nginx-1.6.2.tar.gz

CD nginx-1.6.2

./configure--prefix=/usr/local/nginx--user=nginx--group=nginx && make && make install

Useradd-m-s/sbin/nologin Nginx

Ln-s/usr/local/nginx/sbin/*/usr/local/sbin/

echo "Node_1" >/usr/local/nginx/html/index.html

To establish a firewall rule:

Iptables-i-input-p TCP--dport-j ACCEPT

In addition to the configuration of the Web node server, it is recommended that the contents of the test page not be consistent in order for the test to see the effect

Three: Haproxy's log

Haproxy logs are output to syslog in the system by default, which is not very convenient to view, in order to facilitate the management of Haproxy logs, defined separately in the production environment

1. Modify the options for the log configuration in the Haproxy configuration file:

Log/dev/log local0 Info

Log/dev/log local0 Notice

These two lines of configuration are placed in the Haproxy global Configuration project, where the main haproxy info and notice logs are recorded in separate log files.

2. Modify the Rsyslog configuration

Haproxy-related configuration is independently defined to haproxy.conf and stored under/ETC/RSYSLOG.D, and all configuration files under this directory are automatically loaded at rsyslog startup

Touch/etc/rsyslog.d/haproxy.conf

Vim/etc/rsyslog.d/haproxy.conf

Add the following content:

if ($programname = = ' Haproxy ' and $syslogseverity-text = = ' Info ') then-/var/log/haproxy/haproxy-info.log

& ~

if ($programname = = ' Haproxy ' and $syslogseverity-text = = ' Info ') then-/var/log/haproxy/haproxy-notice.log

& ~

This section configures the Haproxy info log to/var/log/haproxy/haproxy-info.log and logs the notice log to/var/log/haproxy/haproxy-notice.log, which " & ~ "indicates that Rsyslog stops processing this information after it is written to the log file, and this configuration syntax is written in the Rainerscript scripting language.

Four: Haproxy parameter optimization

Maxconn maximum number of connections recommended use 10240

Daemon Daemon mode can use non-daemon default

Nbproc the number of concurrent processes for load balancing is recommended to be equal to or twice times the current server CPU core

Retries Retry count to cluster node, node multiple concurrency, set to 2 to 3 times

Option Http-server-close active shutdown HTTP request option in a production environment use this option to prevent HTTP connection buildup due to timeout time setting too long

Timeout http-keep-alive long connection time-out (10s)

Timeout Http-request http request time-out (5~10s) increases the speed of HTTP connection release

Timeout client client time-out




This article is from the "11853028" blog, please be sure to keep this source http://tanhong.blog.51cto.com/11853028/1886909

Haproxy Building a Web cluster

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.