Sunday, February 05, 2012

Use HAProxy as http load balancer (1)

How to setup configuration files
- Example

- Configuration

global #global section
daemon # run the process in background
# max concurrent connection frontend could accept
# excess connections will be queued by the system in the socket's listen queue and will be served once a connection closes
maxconn 6000

defaults #proxy section
option httplog # enable http request log in richer format
timeout connect 5000ms # maximum time for waiting a connection attempt to a server success
timeout client 50000ms # maximum time for client connection, unspecified: infinite
timeout server 50000ms # maximum time for server, unspecified: infinite

frontend http-in #proxy section
bind *:8001 # specify listen address and port
mode http # specify running protocol, { tcp|http|health }
# declare access list, acl aclname criterion [flags] [operator] value
acl audio path_reg /AudioService/Browse/.*
acl audio path_reg /AudioService/Search/.*
acl audio path_reg /AudioService/Download/.*
acl audio path_reg /AudioService/Rate/.*
acl audio path_reg /AudioService/Play/.*
acl video path_reg /VideoService/Browse/.*
acl video path_reg /VideoService/Search/.*
acl video path_reg /VideoService/Download/.*
acl video path_reg /VideoService/Rate/.*
acl video path_reg /VideoService/Play/.*
# use specific backend if/unless an ACL-based (access list) condition is matched
use_backend AudioServiceGroup if audio
use_backend VideoServiceGroup if video

backend AudioServiceGroup #proxy section
mode http
# declare backend server, server name address param*
server s1 10.10.101.11:80 maxconn 200
server s2 10.10.101.12:80 maxconn 200
server s3 10.10.101.13:80 maxconn 200

backend VideoServiceGroup #proxy section
mode http
server s4 10.10.101.14:80 maxconn 200
server s5 10.10.101.15:80 maxconn 200
server s6 10.10.101.16:80 maxconn 200

ref:
- haproxy official website
- haproxy document
- matching criteria
- server options

No comments:

Post a Comment