资源下载
实现
<code><span>Engine</span><span>name</span>=<span>"Catalina"</span><span>defaultHost</span>=<span>"localhost"</span>>?</code>
若加上jvmRoute,会导致redis内容占用过大,jvmRoute会被循环复制进redis中,导致内存爆满。如下图:
<code><span>Valve</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionHandlerValve"</span> /><span>Manager</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionManager"</span><span>host</span>=<span>"192.168.25.132"</span><span>port</span>=<span>"6379"</span><span>database</span>=<span>"0"</span><span>maxInactiveInterval</span>=<span>"60"</span> /></code>
上述方式是整个Tomcat都采用redis保存Session,我们也可以使用在conf\Catalina\localhost下加入一个xml启动项目,此时是单独对该项目采用redis,如加入一个ROOT.xml,代码如下:
<code><span><?xml version='1.0' encoding='utf-8'?></span><span>Context</span><span>path</span>=<span>"/"</span><span>docBase</span>=<span>"F:\learn\tomcat\ewebsite"</span><span>debug</span>=<span>"0"</span><span>privileged</span>=<span>"true"</span>><span>Valve</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionHandlerValve"</span> /><span>Manager</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionManager"</span><span>host</span>=<span>"192.168.25.132"</span><span>port</span>=<span>"6379"</span><span>database</span>=<span>"0"</span><span>maxInactiveInterval</span>=<span>"60"</span> /><span><span>Context</span>></span></code>
测试
测试方式请参考《Tomcat集群与Session共享 + Nginx负载》
同时查看Redis中的keys,已将SessoionId保存,可以flushdb清空redis数据,SessoionId将改变
以上就介绍了Redis+Nginx+Tomcat实现Session共享,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。