State Server实现多机器多站点 Session 共享 全手记
网络环境有2台windows 2008 (192.168.1.71,192.168.1.72) 需要部署成 WebFarm,提高容错性。 网站部署在2台机器上的2个站点,如何才能做到Session的共享呢?
第一个方法:不共享。用HAProxy作负载均衡,它支持session会话保持功能,即同一个IP只转发到一台服务器上。基于cookies的session sticky
第二个方法:State Server 。
选择71作为State Server,修改注册表的[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters]中的AllowRemoteConnection,把它改成1,默认是不允许远程连接的,值为0,另外在这里也可以改Port 端口号,默认的是42424端口。启动asp.net state service。
在71,72上的IIS新建站点,不要用默认站点,文件路径,网站名字都要一样,SiteID也要一样。
修改web.config。 在每个站点的web.config上都设置如下: (machinekey 可以在iis管理界面自动生成)
<sessionState mode="StateServer" stateConnectionString=
"tcpip=192.168.1.71:42424" timeout="30" cookieless="false" /> <machineKey validationKey="我的validationKey"
decryptionKey="我的decryptionKey"
validation="SHA1" decryption="AES" />
网上很多文章讲到这一步就完了,但这样的话,2个站点所产生的SessionID还是不同了, 一定要确保这些共享session的网站使用相同的一级域名,比如 www.test.com,www1.test.com,www2.test.com等等的.test.com域的网站. 测试时一定要用域名访问,假如用ip,localhost等访问,SessionID是不同的
你可以在测试机器上修改C:\WINDOWS\system32\drivers\etc\host文件,增加2行
192.168.1.71 www.test.com
192.168.1.72 www1.test.com
然后在web.config增加一句
<system.web>
<!-- 让其在跨站点访问时,使SESSION能共用 -->
<httpCookies domain="test.com" />
</system.web>
做一个aspx测试页面, 把Session.Session显示出来,看是不是一样,在71的WebSite 设置Session["abc"]="def", 然后在72上面Get Session看能不能取到值
第三个方法: 放在Sql Server里, 但我不赞成使用这个,因为sql server的连接数有限,很容易成为瓶颈
<sessionState mode="SQLServer" sqlConnectionString="Data Source=127.0.0.1;User ID=ASPState;Password=ASPState;" timeout="60" />
第四个方法:放在MemCache里,自己实现custom的SessionStateProvider.
网上关于memcache的有2个实现,一个是enyim的https://github.com/enyim/memcached-providers (这个依赖CouchDB)
另外一个是http://memcachedproviders.codeplex.com/(只实现了Session,没实现OutputCacheProvider,这个net4.0才有),
他们也是用sessionID或者SessionID+ WebSiteName作为MemCache的Key的。这里就不详细说明了
State Server实现多机器多站点 Session 共享 全手记的更多相关文章
- 多服务器之间Session共享
原理:多个服务器间想共享session,就相当于共享取多台主机上的一个变量,所以共享的思路就是让大家都能读取变量,实现的方法可以通过将session保存到专门的一个服务器上,所有服务器都去请求数据,也 ...
- Unable to make the session state request to the session state server处理
Server Error in '/' Application. Unable to make the session state request to the session state serve ...
- Unable to make the session state request to the session state server处理方法
Server Error in '/' Application. Unable to make the session state request to the session state serve ...
- 关于ASP.NET Session State Server
最近公司开发的一个网站因为访问量增大,需要添加多台Web Server来进行负载均衡. 但是在做负载均衡前需要将一些原来固定存储在单台机器上的东西分离出来,使之能单独存在在一个独立的机器上,其中就有S ...
- 如何应对Session丢失》》State Server
Session丢失已经是一种习以为常的问题了,在自己也了解一些如何解决的问题,但是也一直没有机会去用,现在由于新的项目要在B/S下开发,所以不得不让我考虑Session的问题. 解决session丢失 ...
- 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- 转: 解决【Unable to make the session state request to the session state server】
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...
- ASP.NET State Server 服务 sessionState
在发布ASP.NET网站的时候,出现state server错误:Server Error in '/' Application.----------------------------------- ...
- 关于多台机器之前session共享,sessionState mode="StateServer" 问题的困扰
.net 多台机器共享session是很老的技术,一直很少用到session. 最近就出现了一个问题:三台前端,其中一台保存的session值死活不对,一样的环境,一样的配置文件,就是和另外两台获得的 ...
随机推荐
- DIV背景图片定位问题
<div class="custom-topNavigation_shadow"> </div> 正确写法 .custom-topNavigation_ ...
- 如何获取模拟器安装的app的位置
你可以死记下地址格式, 但是一旦不同的xcode和模拟器版本改变变了地址, 又得记, 从活动管理器里其实是可以直接查看的: Launch the app in the simulator Open A ...
- appium的xpath定位问题及常用方法
关于类似的帖子好像很多,但是没有找到具体能帮我解决问题的办法.还是自己深究了好久才基本知道app上面的xpath定位和web上的不同点: 先放一个图: A,先说说不用xpath的场景,一般是用于存在i ...
- saltstack系列1之salt-api配置与使用
salt-api salt-api是我们通过restful-api调用salt-master的接口,且调用的时候必须通过认证才能调用,认证的用户为系统用户,下面就说说如何配置salt-api. 不带S ...
- JIRA 初体验
JIRA 使用神奇的JQL查询数据,很nice啊 ! 官网API: https://docs.atlassian.com/jira/REST/latest/#d2e2344 测试一下search: ...
- Nine-patch
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch This NinePatch defi ...
- Array常用函数收藏
1.isArray 语法:Array.isArray(obj) 说明:判断一个对象是否是数组. 例如: Array.isArray([]); Array.isArray([1]); Array.isA ...
- 源码分析三(Vector与ArrayList的区别)
前面讨论过ArrayList与LinkedList的区别,ArrayList的底层数据结构是数组Object[],而LinkedList底层维护 的是一个链表Entry,所以对于查询,肯定是Array ...
- go fmt格式化----“占位符”
https://studygolang.com/articles/2644 https://studygolang.com/static/pkgdoc/pkg/fmt.htm
- 使用monkey技术修改python requests模块
例如请求前和请求后各来一条日志,这样就不需要在自己的每个代码都去加日志了. 其实也可以直接记录'urllib3.connectionpool' logger name的日志. 修改了requests ...