How to install and configure HAProxy in linux

Source: Internet
Author: User
Tags haproxy
The configuration of HAProxy is divided into five parts. Of course, these components are not mandatory and can be selected as needed. Global: The parameter is process-level, usually related to the Operating System (OS. These parameters are generally set only once. If the configuration is correct, you do not need to modify defaults again: to configure the default parameter, which

HAProxy Configuration

The HAProxy configuration is divided into five parts. Of course, these components are not required. You can select some as needed.
Global: The parameter is process-level, usually related to the Operating System (OS. These parameters are generally set only once. If the configuration is correct, you do not need to modify them again.
Defaults: used to configure Default parameters. These parameters can be configured to the frontend, backend, and listen components.
Frontend: the front-end virtual node that receives requests. Frontend can specify the backend Based on the Rules (which can be dynamically selected ).
Backend: backend ServiceClusterIs a real server. One Backend corresponds to one or more physical servers.
Listen: Combination of Frontend and Backend.

The following are some common configurations of HAProxy. This configuration is used to describe the configurations of some common features of HAProxy. For detailed configurations, see the document files in the doc directory under the installation directory, or go to "http: // cn.Haproxy. Org /"

Download Chinese configuration instructions

Configuration File example:

Global

# Global log configuration where the log level is [err warning info debug]

# Local0 is a log device and must be one of the following 24 standard syslog devices:

# Kern user mail daemon auth syslog lpr news

# UuCpCron Au2FtpNtp audit alert cron2

# Local0 local1 local2 local3 local4 local5 local6 local7

# But previously defined local0 in the/etc/syslog. conf file, so

# Local0 is also used here

Log 127.0.0.1 local0 info # [err warning info debug]

# Maximum number of connections

Maxconn 4096

# User

User admin

# Group

Group admin

# Enable the HAProxy process to run in the background. This is the recommended running mode.

Daemon

# Create four processes to run in deamon mode. This parameter requires that the running mode be set to "daemon"

Nbproc 4

# Change the p of all processesIdThe user who writes the file to start the process must have the permission to access the file.

PiDfIle/home/admin/haproxy/logs/haproxy. pid

Ults

# The default mode is {tcp | http | health}, tcp is Layer 4, http is Layer 7, and health only returns OK.

Mode http

# Use http log format

Option httplog

# If the connection fails three times, the server is considered unavailable. You can also set it later.

ReTrIes 3

If the cookie is written into the serverId and the client does not refresh the cookie,

# When the server corresponding to the serverId fails, it is forcibly directed to other healthy servers.

Option rEdIsPatch

# When the server load is high, the link for processing the queue for a long time is automatically terminated.

Option abortoNcLose

# Default maximum number of connections

Maxconn 4096

# Connection timeout

ConTimeOut 5000

# Client timeout

Clitimeout 30000

# Server timeout

Srvtimeout 30000

# = Heartbeat detection timeout

Timeout check2000

# Note: Some parameter values are time, for example, timeout. The time value is usually in milliseconds (MS), but you can also use other units by adding the # suffix.

#-Us: microseconds. 1 microsecond = 1/1000000 second

#-MS: milliseconds. 1 millisecond = 1/1000 second. This is the default.

#-S: seconds. 1 s = 1000 ms

#-M: minutes. 1 m = 60 s = 60000 ms

#-H: hours. 1 h = 60 m = 3600 s = 3600000 ms

#-D: days. 1d = 24 h = 1440 m = 86400 s = 86400000 ms

######## Statistics page configuration ############

Listen admin _StatS

# Listening port

Bind 0.0.0.0: 1080

# Layer-7 http mode

Mode http

# Log Settings

Log 127.0.0.1 local0 err # [err warning info debug]

# Automatic refresh time on the statistics page

Stats refresh 30 s

# Statistics page url

Stats uri/admin? Stats

# Prompt text in the password box on the statistics page

Stats realm Gemini Haproxy

# User name and password settings on the statistics page

Stats auth admin: admin

Stats auth admin1: admin1

# Hide the HAProxy version on the statistics page

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.