基于域名负载均衡的Haproxy配置

global
        log 127.0.0.1 local0 info #[err warning info debug] //日志位置
        maxconn 4096
        daemon #设置成后台运行
        nbproc 1 #进程数量
       # pidfile /home/admin/haproxy/logs/haproxy.pid

defaults
        log     global
        mode    http #默认模式
        option  httplog #http日志格式
        option  dontlognull
        retries 3  #三次失败后认为服务器不可用
        option  redispatch  #如果cookie写入了serverId而客户端不会刷新cookie,当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
        maxconn 2000 #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接默认的最大连接数
        contimeout 5000 #连接超时
        clitimeout 30000 #客户端超时
        srvtimeout 30000 #服务器超时

frontend web_in
        mode http
        maxconn 1000
        bind :80
        acl is_a hdr_beg(host) -i www.abc.test1  #判断域名是不是www.abc.test1,是则给与a服务器集群服务
        acl is_b hdr_beg(host) -i www.abc.test2  #判断域名是不是www.abc.test2,是则给与a服务器集群服务

        use_backend a_server if is_a
        use_backend b_server if is_b

backend a_server
        mode http #http 模式
        stats   uri  /haproxy
        balance roundrobin
        cookie  JSESSIONID prefix
        stats   hide-version
        option  httpclose
        server web1 128.1.87.3:80 check
        server web2 128.1.2.5:80 check


backend b_server
        mode http #http 模式
        stats   uri  /haproxy
        balance roundrobin
        cookie  JSESSIONID prefix

        stats   hide-version
        option  httpclose
        server web1 128.1.87.4:80

posted @ 2013-01-11 21:02  茗迹周  阅读(1312)  评论(0编辑  收藏  举报