haproxy代码

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

转载于:https://www.cnblogs.com/allmdzz/p/11146236.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值