Implementation of session sharing redis for TOMCAT hot deployment

Keywords: Operation & Maintenance xml Session Tomcat Java

JAVA-web Program Tomcat Container Publishing and Conventional Operation

1. Warpackage Publishing

1.1 Place the completed war package directly to% TOMCAT_HOME%/webapps/

1.2 Modify% TOMCAT_HOME%/conf/server.xml to add nodes to the host node

docBase:Project paths, which can be either absolute or relative, are relative webapps 
path:The path to access the project, such as: http://127.0.0.1:8080/demo1 
reloadable:Whether to automatically load new or changed class file. 
debug Attributes and this Engine Relevant Logger The level of detail of debugging information recorded. The larger the number, the more detailed the output. If not specified, the default is 0. That is, the level of detail written to the log file when the program is abnormal.

 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
     
     <Context debug="0" docBase="D:\demo1\web" path="/demo1" privileged="true" reloadable="true"/>

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>


1.3 Modify% TOMCAT_HOME% conf Catalina localhost to add an XML file

The name of xml is either the project name or the project name.
For example: demo1.xml, SO access address is: http://localhost:8080/demo1


<?xml version="1.0" encoding="UTF-8"?> 
<Context docBase="D:\demo1\web" reloadable="true" /> 

2. jar package Publishing

2.1 Under normal conditions.

#java -jar xxxx.jar
 

2.2 If the item is prompted

In the project run, if there is no main list attribute

Manual addition

Open the generated jar with a MANIFEST.MF file open it:

Hair styles do not have Main-Class to perform the main class configuration;

One solution is to manually add Main-Class files

Processing Mode 2: Find a new package for the program and inform the startup that the startup class configuration is missing

3-port configuration

Modify the port in% TOMCAT_HOME%/conf/server.xml

   <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

4 Shared session

4.1 Structural diagram:

Represents the use of redids to store sessions in multiple Tomcats to achieve session sharing

4.2 tomcat configuration information

Request listening port Shutdown listening port AJP listening port
tomcat_1 8080 8005 8009
tomcat_2 8090 8015 8019

4.3 Configuration Modification

tomcat_1 port is configured by default (server.xml is not changed)

Change tomcat_2 port to the following configuration (modify server.xml)

  <Connector port="8090" protocol="HTTP/1.1"  
               connectionTimeout="20000"  
               redirectPort="8443" />  

    <Connector port="8019" protocol="AJP/1.3" redirectPort="8443" />  



4.4 Configure session sharing

Both tomcat_1 and tomcat_2 have to modify contenxt.xml

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />  
  <Manager className="com.radiadesign.catalina.session.RedisSessionManager"  
         host="localhost"   
         port="6379"   
         database="0"   
         maxInactiveInterval="60" />

4.5 Add jar packages

Add these packages to the lib directory in the tomcat directory, which completes the shared session configuration

4.6 Expansion

This example is about redis to achieve session sharing

You can also use other caching components, such as memcahed

Reference address: https://www.cnblogs.com/kevingrace/p/6398672.html

Posted by locomotive on Thu, 15 Aug 2019 23:34:43 -0700