1,haproxy定义cookie并且返回数据给客户端,让客户端第二次请求这个域名下的页面时带上haproxy定义的cookie跟数值(key-value)
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 40000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
① 定义web 监控页面
listen stats
bind 0.0.0.0:1080
stats enable
stats hide-version
stats uri /haproxyadmin 监控页面的详细地址
stats auth admin:admin 验证的账号密码
stats admin if TRUE
② 在frontend 段定义ACL
frontend web
bind :80
acl staticfile path_end .jpg .png .bmp .htm .html .css .js 定义静态页面acl
acl appfile path_end .php
use_backend staticsrvs if staticfile
default_backend appsrvs
③ 设置backend 后端集群组
backend staticsrvs
balance roundrobin
server staticweb 192.168.30.107:80 check inter 3000 rise 3 fall 3
backend appsrvs
balance roundrobin
#option httpchk HEAD /index.html HTTP/1.0 基于head检测url
option httpchk GET /index.html #基于请求get检测url
cookie SRV insert nocache
server appweb1 192.168.30.7:80 check inter 3000 rise 3 fall 3 cookie srv1
server appweb2 192.168.30.7:80 check inter 3000 rise 3 fall 3 cookie srv2