1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| global
log 127.0.0.1 local0 notice //local0是日志设备,info是日志记录级别(err,warning,info,debug),可以在系统日志里查看
maxconn 5535 //HAproxy接受的最大连接数,还要注意linux文件接受的最大连接数,用命令"ulimit -n"看以查看,在/etc/security/limit.conf可以永久修改。
chroot /usr/local/haproxy //
user nobody //进程用户
group nobody //进程组
nbproc 1 //进程可以创建的进程数,建议小于服务器的cpu数
daemon //后台运行
defaults
option httplog //记录http日志
mode http //http模式,不与RFC格式兼容的请求都会被拒绝,还有TCP模式作为4层转发,多用于SSL,SSH,SMTP
option dontlognull
retries 3 //连接失败后重试此树
maxconn 5535
timeout connect 5s //连接后端服务器的最长等待时间
timeout server 30s //服务端回应客户端数据发送的最长等待时间
timeout client 30s //连接客户端发送数据的最长等待时间
timeout check 5s //每5s检验一次后端服务器
stats refresh 30s //后端服务器健康状态刷新时间
stats uri /stats //通过浏览器可以查看业务状态,例如:www.w4ya.com/stats
stats realm welcome //提示信息
stats auth admin:dragon123 //查看HA监控后端状态时的帐号密码验证
stats hide-version //不显示haproxy的版本信息
frontend www
bind :80
acl host_web hdr(host) -i www.draon.com //定义ACL匹配域名www.dragon.com
acl url_static path_end .html .css .jpg //定义ACL匹配静态文件
acl host_test hdr_dom(host) -i www.test.com //定义ACL匹配域名www.test.com
acl url_dynamic path_end .php .jsp //定义ACL匹配动态
use_backend web-dynamic-server if host_web url_dynamic
//如果域名为www.dragon.com和页面是动态的,则把请求调度给web-dynamic-server
use_backend web-static-server if host_web url_static || host_web
//如果域名为www.test.com和页面是静态的,或则域名为www.dragon.com,则把请求调度给web-static-server
use_backend test-dynamic-server if host_test url_dynamic
use_backend test-static-server if host_test url_static || host_test
backend web-static-server //定义www.dragon.com动态页面的管理集群
mode http
balance roundrobin //负载均衡算法为轮询
option redispatch // 保持cookie环境,使客户机的session持久连接。
option abortonclose //在服务器高负载时,自动放弃队列中处理时间较长的连接
option httpchk GET /index.html /通过请求后端http服务的页面,判断状态
server web01 192.168.1.118:80 check inter 2000 rise 2 fall 3 weight 10
//后端响应的服务器,根据需求可能会有多个。
ckeck:表示启用对后端服务器的健康检查
rise:由故障切换会正常需要进行的检查次数
fall:由正常到故障认定检查的次数
weight:权重
backend web-dynamic-server
mode http
option redispatch
option abortonclose
option httpchk GET /index.php
balance roundrobin
server web02 192.168.1.111:80 check inter 2000 rise 2 fall 3 weight 10
backend test-static-server
mode http
option redispatch
option abortonclose
option httpchk GET /index.html
balance roundrobin
server test01 192.168.1.117:80 check inter 2000 rise 2 fall 3 weight 10
backend test-dynamic-server
mode http
option redispatch
option abortonclose
option httpchk GET /index.php
balance roundrobin
server test02 192.168.1.114:80 check inter 2000 rise 2 fall 3 weight 10
HA1和HA2的配置文件都是一样的。
|