Build a Web cluster using Haproxy

Source: Internet
Author: User
Tags haproxy rsyslog

Haproxy is currently a popular cluster scheduling tool.

Haproxy comparison with LVs and Nginx

LVS Performance is the best, but the construction is relatively complex

Nginx upstream module support cluster function, but the cluster node health Check function is not strong, performance is not Haproxy Good

HTTP request

The protocol used to access a Web site through a URL is an HTTP protocol, which is generally referred to as an HTTP request.

The way HTTP is requested is the Get mode and post mode.

The normal status code is 2XX, 3xx, abnormal status code is 4xx, 5xx

Features of the cluster: High performance, high availability

load Balancing common scheduling algorithm

RR ( Round Robin ): Polling Schedule

LC ( least Connections ): Minimum number of connections  

SH ( Source Hashing ): Based on source access scheduling

Experimental topological diagram

a single Haproxy Server, two units Nginx server (or Apache server), build two different websites (easy to test the cluster), a client to test online.

Experimental process

First, operate on the Haproxy server

1. Compile and install Haproxy

2. Setting up the Haproxy configuration file

Introduction to 3.Haproxy Configuration items

The Haproxy profile is typically three parts, that is, the global configuration, default configuration, and listen (app component configuration).

4. Create a self-launching script


5. Site testing in Nginx (Apache) (two Web server operations are consistent)

6. Verification by the client

7.Haproxy of logs

The Haproxy log is output to syslog in the system by default, it is not very convenient to view, in order to better manage the Haproxy log, we are generally defined separately in the production environment.

(1) Modify the options for the log configuration in the Haproxy configuration file

After the configuration is complete, restart the Haproxy service.

(2) Modify Rsyslog configuration

For ease of administration, the Haproxy-related configuration is independently defined to haproxy.conf and placed under/etc/rsyslog.d/, and all configuration files under this directory are automatically loaded at rsyslog startup.

Add the following content

This part of the configuration is to record the Haproxy info log to/var/log/haproxy/haproxy-info.log, notice log to/var/log/haproxy/haproxy-notice.log, where "& ~" means that Rsyslog stops processing this information after the log file is written to it.

Then save the configuration file and restart the Rsyslog service to complete the Rsyslog configuration.

(3) Test log file

Parameter optimization for 8.Haproxy

Parameters
Parameter description
Optimization recommendations
Maxconn
Maximum number of connections
Recommended Use 10240
Daemon
Daemon mode
Recommended Use
Nbproc
Number of concurrent processes with load balancing
Recommended equal or twice times the number of CPU cores for the current server
Retries
Retry Count
This parameter is mainly used to check the cluster node, if the node is many, and the concurrency is large, set to 2 this or 3 times, in the case of a few server nodes, you can set 5 or 6 times
Option Http-server-close
Proactively turn off HTTP request options
Recommended to avoid HTTP connection buildup due to timeout time setting too long
Timeout http-keep-alive
Long Connection Timeout time
Can be set to 10s
Timeout http-request
HTTP request time-out
It is recommended to set this time to 5~10s to increase the speed of HTTP connection release
Timeout client
Client timeout time
The recommended setting is 1min or so.

Extended

added a haproxy in,used to do backup, install keepalived on two haproxy , two haproxy steps consistent, just a few differences in configuration file

First, the settings of the primary server

Based on the front, follow the steps below

1. Installing keepalived

2. Modify the keepalived configuration file

Vim/etc/keepalived/keepalived.conf

The above content in the configuration file must be added or modified, the following can be determined according to their own circumstances

After the configuration is complete, restart the service

Note: The firewall turns on the 224.0.0.18 port, which is the keepalived multicast address.

Second, from the server configuration

    1. Install the Haproxy service and modify the configuration file (same way)

    2. Installing the Keepalived service (same way)

    3. Modifying the keepalived configuration file

Just modify the router_id, state, and priority parameters, and others will be consistent.

4. Restart keepalived Service, set firewall rules

Third, the client to access, access to virtual ip:192.168.1.100

You can turn off the primary server and test it to access the site, which enables the Haproxy high-availability feature.

Build a Web cluster using Haproxy

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.