单点登陆

学习内容:

单点登陆


学习笔记:

1、背景:

a) Http协议无状态, 使用session、cookie缓存相关信息;
b) 集群环境下通过负载均衡做到session共享

2、 负载均衡:

从实施方面分为硬件均衡和软件均衡, 它们又分为四层均衡和七层均衡

{
物理层:主定义物理设备标准;
数据链路层:主定义如何格式化数据为帧为单位进行传输;
网络层:主连接不同地域设备之间的定位与连接;
传输层:主定义协议与端口号;
会话层:主通过传输层建立数据连接的通路;
表示层:主确保接收的信息或发送信息的格式可以被读取或格式转化;
应用层:为应用程序创建网络连接
}
{
链路层:物理层,数据链路层;
网络层;
传输层;
应用层:应用层,表示层,会话层
}
四层均衡:即根据传输层的 IP+Port 进行分流;
七层均衡:即根据应用层的 URI 进行风流;
软件均衡:lvs,为四层协议;HaProxy、Ngnix为七层协议, 七层协议数据流量比较大;

负载均衡算法:
1、轮询或加权轮询
2、随机
3、Hash
4、最小连接数

负载均衡策略:
1、Session Sticky:确保同一个Ip请求到同一台机器,比如使用 Hash,但是如果遇到重启或宕机就会丢失session;
2、Session Copy:通过 tomcat 配置进行 session 相互备份共享,但是如果集群太大则会占用较大的网络和内存;
3、session-redis:将session统一从某个存储设备获取, 这要求这个存储设备的可用性要高;
4、Cookie Base:不依赖服务依赖的session,在Cookie直接获取Token(JWT)

3、spring-session:

applicationContext-session.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.3.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
">
    
    <context:property-placeholder location="classpath:redis.properties"/>
    <bean id="sessionRepositoryFilter" class=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值