To build haproxy, you have to choose your target OS amongst the following ones
and assign it to the TARGET variable :
- linux22 for Linux 2.2
- linux24 for Linux 2.4 and above (default)
- linux24e for Linux 2.4 with support for a working epoll (> 0.21)
- linux26 for Linux 2.6 and above
- solaris for Solaris 8 or 10 (others untested)
- freebsd for FreeBSD 5 to 8.0 (others untested)
- openbsd for OpenBSD 3.1 to 4.6 (others untested)
- cygwin for Cygwin
- generic for any other OS.
- custom to manually adjust every setting
示例要求:将 http://yourdomain/file1 , http://yourdomain/file1_1 , http://yourdomain/file1_2 等如此url定位到一台cache server
配置(简要部分):
defaults //默认配置
mode http //默认采用http模式,可以配置tcp来做4层消息转发
option httplog //采用http日志格式
retries 3 //三次连接失败就认为是服务器不可用,主要是通过后面的check配置来实现服务器状态检查
maxconn 2000 //最大连接数
contimeout 5000 //连接超时时间
clitimeout 50000 //客户端连接超时时间
srvtimeout 50000 //服务端连接超时时间
stats uri /stats //服务器状态统计查看页面
frontend picture
bind 192.168.0.2:80
mode http
log global
option httplog
default_backend pic_server
backend pic_server //后端节点定义
mode http
balance uri len 6 // hash截取的uri长度
server pic1 192.168.0.4:80 check
server pic2 192.168.0.5:80 check
备注:这是官方文档对balance的uri调度算法的解释。
uri The left part of the URI (before the question mark) is hashed
and divided by the total weight of the running servers. The
result designates which server will receive the request. This
ensures that a same URI will always be directed to the same
server as long as no server goes up or down. This is used
with proxy caches and anti-virus proxies in order to maximize
the cache hit rate. Note that this algorithm may only be used
in an HTTP backend. This algorithm is static by default,
which means that changing a server's weight on the fly will
have no effect, but this can be changed using "hash-type".
This algorithm support two optional parameters "len" and
"depth", both followed by a positive integer number. These
options may be helpful when it is needed to balance servers
based on the beginning of the URI only. The "len" parameter
indicates that the algorithm should only consider that many
characters at the beginning of the URI to compute the hash.
Note that having "len" set to 1 rarely makes sense since most
URIs start with a leading "/".
The "depth" parameter indicates the maximum directory depth
to be used to compute the hash. One level is counted for each
slash in the request. If both parameters are specified, the
evaluation stops when either is reached.
参考资料:
http://blog.csdn.net/cenwenchu79/archive/2009/08/04/4409343.aspx
http://blog.csdn.net/cenwenchu79/archive/2009/08/04/4409300.aspx
http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
http://bbs.linuxtone.org/thread-1079-1-2.html