Home >Backend Development >PHP Tutorial >Redis+Nginx+Tomcat realizes session sharing

Redis+Nginx+Tomcat realizes session sharing

WBOY
WBOYOriginal
2016-07-29 08:58:24955browse

Resource download

  • tomcat-redis-session-manager: https://github.com/jcoleman/tomcat-redis-session-manager/downloads
  • Build jdk7 + mysql5.5 + under CentOS-6.5-64 bit Tomcat7 + nginx environment construction
  • To build nginx + tomcat cluster, please refer to "Tomcat Cluster and Session Sharing + Nginx Load"
  • Redis setup, please refer to "Centos6.5 Installation redis3.0.7"
  • Local download: jedis-2.2. 1.jar+commons-pool-1.6.jar+tomcat-redis-session-manager-1.2-tomcat-7.jar

implementation

  • restore the conf/server.xml configuration under two Tomcats, especially the following In the node, do not add jvmRoute.
<code><span>Engine</span><span>name</span>=<span>"Catalina"</span><span>defaultHost</span>=<span>"localhost"</span>>?</code>

If jvmRoute is added, the redis content will take up too much, and jvmRoute will be copied into redis in a loop, causing the memory to be full. As shown below:
Redis+Nginx+Tomcat realizes session sharing

  • Modify the two tomcat configuration files conf/context.xml
<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>

The above method is that the entire Tomcat uses redis to save the Session. We can also add an xml startup project under confCatalinalocalhost. At this time, Use redis for this project alone, such as adding a ROOT.xml, the code is as follows:

<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>
  • Add the corresponding jar under Tomcat's lib
    Redis+Nginx+Tomcat realizes session sharing

Test

For testing methods, please refer to "Tomcat Cluster and Session Sharing + Nginx Load》
At the same time, check the keys in Redis. The SessoionId has been saved. You can flushdb to clear the redis data. The SessoionId will change
Redis+Nginx+Tomcat realizes session sharing

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the implementation of Session sharing by Redis+Nginx+Tomcat, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn