HAProxy---基于cookie的会话保持

基于cookie会话保持,浏览器有这个cookie值,就访问对应的web后端服务器

[root@centos7 ~]#cat /etc/haproxy/haproxy.cfg 
global
    log         127.0.0.1 local2 info

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     100000
    user        haproxy
    group       haproxy
    daemon
    nbproc 2
    cpu-map 1 0
    cpu-map 2 1

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats mode 600 level admin

    # utilize system-wide crypto-policies
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  http-keep-alive
    option forwardfor       except 127.0.0.0/8
    timeout connect         300s
    timeout client          300s
    timeout server          300s
    timeout check           5s
    maxconn                 100000


#---------------------------------------------------------------------
# cookie test
#---------------------------------------------------------------------
listen web_host
    bind 10.0.0.17:80
    mode http
    balance roundrobin #动态权重轮询
    log global
    cookie SERVER-COOKIE insert indirect nocache
    server web1 10.0.0.8:80 cookie web1 check inter 3000 fall 3 rise 5
    server web2 10.0.0.18:80 cookie web2 check inter 3000 fall 3 rise 5

效果:
配置后:第一次访问,轮询一台web后端,服务器下载cookie,后面基于cookie访问至固定的服务器,除非清除cookie
在这里插入图片描述
在这里插入图片描述

[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web2" 10.0.0.17
10.0.0.18
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web2" 10.0.0.17
10.0.0.18
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web2" 10.0.0.17
10.0.0.18
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web2" 10.0.0.17
10.0.0.18
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web2" 10.0.0.17
10.0.0.18
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web1" 10.0.0.17
10.0.0.8
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web1" 10.0.0.17
10.0.0.8
[root@centos7 ~]#curl --cookie "SERVER-COOKIE=web1" 10.0.0.17
10.0.0.8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值