HAProxy负载均衡保持客户端和服务器Session亲缘性的三种方式
2015-03-09 10:48
387 查看
1 用户IP 识别
haroxy 将用户IP经过hash计算后 指定到固定的真实服务器上(类似于nginx 的IP hash 指令)
配置指令 balance source
2 cookie 识别
haproxy 将WEB服务端发送给客户端的cookie中插入(或添加加前缀)haproxy定义的后端的服务器COOKIE ID。
配置指令例举 cookie SESSION_COOKIE insert indirect nocache
用firebug可以观察到用户的请求头的cookie里 有类似" Cookie jsessionid=0bc588656ca05ecf7588c65f9be214f5; SESSION_COOKIE=app1" SESSION_COOKIE=app1就是haproxy添加的内容
3 session 识别
haproxy 将后端服务器产生的session和后端服务器标识存在haproxy中的一张表里。客户端请求时先查询这张表。
配置指令例举 appsession JSESSIONID len 64 timeout 5h request-learn
#haproxy -f haproxy.cfg -V
#haproxy.cfg
global
log 127.0.0.1 local0 info
maxconn 4096
user haproxy
group haproxy
daemon
nbproc 1
pidfile /var/run/haproxy.pid
defaults
mode http
maxconn 2000
contimeout 5000
clitimeout 30000
srvtimeout 30000
option httplog
option redispatch
option abortonclose
retries 3
listen admin_stats
bind 113.106.185.245:443
mode http
log 127.0.0.1 local0 err
stats uri /qhappy_stats
stats realm itindex.net\ Qhappy
stats auth qhappy:qhappy
stats refresh 5s
listen site_status
bind 113.106.185.245:445
mode http
log 127.0.0.1 local0 err
monitor-uri /site_status
frontend WEB_SITE
bind 0.0.0.0:8080
mode http
log global
option httplog
option httpclose
option forwardfor
acl COOKIE hdr_reg(host) -i ^(cookie.itindex.net)
acl SOURCE hdr_reg(host) -i ^(sourceip. itindex .net)
acl APPSESSION hdr_reg(host) -i ^(appsession. itindex .net)
acl NOSESSION hdr_reg(host) -i ^(nosession. itindex .net)
use_backend COOKIE_srv if COOKIE
use_backend SOURCE_srv if SOURCE
use_backend APPSESSION_srv if APPSESSION
use_backend NOSESSION_srv if NOSESSION
# default_backend ai_server
backend COOKIE_srv
mode http
cookie SESSION_COOKIE insert indirect nocache
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend SOURCE_srv
mode http
balance source
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend APPSESSION_srv
mode http
appsession JSESSIONID len 64 timeout 5h request-learn
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend NOSESSION_srv
mode http
balance roundrobin
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend ai_server
mode http
balance roundrobin
cookie SERVERID
server REALsrv_70 184.82.239.70:80 cookie 2 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 1 check inter 1500 rise 3 fall 3 weight 1
#Cookie
listen appli1-rewrite 0.0.0.0:80
mode http
option httplog
option dontlognull
option httpclose
option forwardfor
cookie SESSION_COOKIE insert indirect nocache
#balance roundrobin
server app1_1 172.20.37.249:8080 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 172.20.12.145:80 cookie app1inst2 check inter 2000 rise 2 fall 5
#IP
listen appli1 0.0.0.0:90
mode http
option httplog
option dontlognull
log 127.0.0.1 local3
cookie JSESSIONID rewrite
balance source
option httpchk GET /payCardSys/login.jsp
stats uri /stats
stats auth admin:admin
server app1_1 10.112.56.66:6601 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 10.112.56.67:6702 cookie app1inst2 check inter 2000 rise 2 fall 5
转载地址:http://itindex.net/blog/2012/07/24/1343118758531.html
haroxy 将用户IP经过hash计算后 指定到固定的真实服务器上(类似于nginx 的IP hash 指令)
配置指令 balance source
2 cookie 识别
haproxy 将WEB服务端发送给客户端的cookie中插入(或添加加前缀)haproxy定义的后端的服务器COOKIE ID。
配置指令例举 cookie SESSION_COOKIE insert indirect nocache
用firebug可以观察到用户的请求头的cookie里 有类似" Cookie jsessionid=0bc588656ca05ecf7588c65f9be214f5; SESSION_COOKIE=app1" SESSION_COOKIE=app1就是haproxy添加的内容
3 session 识别
haproxy 将后端服务器产生的session和后端服务器标识存在haproxy中的一张表里。客户端请求时先查询这张表。
配置指令例举 appsession JSESSIONID len 64 timeout 5h request-learn
#haproxy -f haproxy.cfg -V
#haproxy.cfg
global
log 127.0.0.1 local0 info
maxconn 4096
user haproxy
group haproxy
daemon
nbproc 1
pidfile /var/run/haproxy.pid
defaults
mode http
maxconn 2000
contimeout 5000
clitimeout 30000
srvtimeout 30000
option httplog
option redispatch
option abortonclose
retries 3
listen admin_stats
bind 113.106.185.245:443
mode http
log 127.0.0.1 local0 err
stats uri /qhappy_stats
stats realm itindex.net\ Qhappy
stats auth qhappy:qhappy
stats refresh 5s
listen site_status
bind 113.106.185.245:445
mode http
log 127.0.0.1 local0 err
monitor-uri /site_status
frontend WEB_SITE
bind 0.0.0.0:8080
mode http
log global
option httplog
option httpclose
option forwardfor
acl COOKIE hdr_reg(host) -i ^(cookie.itindex.net)
acl SOURCE hdr_reg(host) -i ^(sourceip. itindex .net)
acl APPSESSION hdr_reg(host) -i ^(appsession. itindex .net)
acl NOSESSION hdr_reg(host) -i ^(nosession. itindex .net)
use_backend COOKIE_srv if COOKIE
use_backend SOURCE_srv if SOURCE
use_backend APPSESSION_srv if APPSESSION
use_backend NOSESSION_srv if NOSESSION
# default_backend ai_server
backend COOKIE_srv
mode http
cookie SESSION_COOKIE insert indirect nocache
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend SOURCE_srv
mode http
balance source
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend APPSESSION_srv
mode http
appsession JSESSIONID len 64 timeout 5h request-learn
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend NOSESSION_srv
mode http
balance roundrobin
server REALsrv_70 184.82.239.70:80 cookie 11 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 12 check inter 1500 rise 3 fall 3 weight 1
backend ai_server
mode http
balance roundrobin
cookie SERVERID
server REALsrv_70 184.82.239.70:80 cookie 2 check inter 1500 rise 3 fall 3 weight 1
server REALsrv_120 220.162.237.120:80 cookie 1 check inter 1500 rise 3 fall 3 weight 1
#Cookie
listen appli1-rewrite 0.0.0.0:80
mode http
option httplog
option dontlognull
option httpclose
option forwardfor
cookie SESSION_COOKIE insert indirect nocache
#balance roundrobin
server app1_1 172.20.37.249:8080 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 172.20.12.145:80 cookie app1inst2 check inter 2000 rise 2 fall 5
#IP
listen appli1 0.0.0.0:90
mode http
option httplog
option dontlognull
log 127.0.0.1 local3
cookie JSESSIONID rewrite
balance source
option httpchk GET /payCardSys/login.jsp
stats uri /stats
stats auth admin:admin
server app1_1 10.112.56.66:6601 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 10.112.56.67:6702 cookie app1inst2 check inter 2000 rise 2 fall 5
转载地址:http://itindex.net/blog/2012/07/24/1343118758531.html
相关文章推荐
- HAProxy负载均衡保持客户端和服务器Session亲缘性的三种方式
- haproxy负载均衡保持客户端和服务器Session亲缘性的三种方式:
- Haproxy的三种保持客户端会话保持方式
- android客户端向服务器通信的三种方式的使用
- 客户端与服务器进行交互的三种方式
- Web服务器与客户端三种http交互方式
- C#三种WCF网络客户端的实现方式
- Android 客户端与服务器交互方式
- ExtJS提交服务器的三种方式
- 客户端与服务器会话跟踪的三种方法
- EXT提交服务器的三种方式
- 使用get,post,httpclient三种方式向服务器提交文本数据
- 服务器和客户端的交互方式(Socket,http协议)和各自特点适用范围
- EXT提交服务器的三种方式
- 构造服务器的三种方式
- 在exchange 2007服务器前架了一个防火墙,outlook客户端用MAPI方式连接不了服务器?
- HAProxy 配置负载均衡 可以测量服务器监控状况,动态分配
- 话说YUM安装服务器的搭建(ftp方式搭建)--以及客户端设置
- EXT提交服务器的三种方式(转)
- 无法向会话状态服务器发出会话状态请求。请确保已启动 ASP.NET State service,并且客户端和服务器端口保持相同。