首页 > 其他分享 >基于tomcat集群配置session会话保持

基于tomcat集群配置session会话保持

时间:2022-08-25 10:33:35浏览次数:66  
标签:多播 tomcat -- 0.0 会话 session

基于tomcat集群配置session会话保持

  • 不配置会出现的错误:nginx分发登录服务器是A,而登录后的页面分发到服务器B,那么没有会话保持,导致无法跳转页面
  • 修改/opt/tomcat/tomcat8/apache-tomcat-8.5.9/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
		connectionTimeout="20000"
               	maxThreads="15" 
		minSpareThreads="2" 
		maxSpareThreads="5" 
		acceptCount="100"
               	redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat188">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.10.0.4" port="45564" frequency="500" dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="实际地址" port="4000" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="/"/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="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 %D %F %I" />

      </Host>
    </Engine>
  </Service>
</Server>

  • 修改/opt/tomcat/tomcat8/apache-tomcat-8.5.9/webapps/ROOT/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
		  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">
<distributable/>
</web-app>
  • 部署多台机子的时候需要注意多播及UDP端口是否开放

    • 您的网络接口是否启用了多播?
    ifconfig eth0 MULTICAST
    
    • 是否存在到您的网络接口的多播路由?
    route add -host 228.0.0.4 dev eth0
    
    • windows默认情况下是开通组播服务的,但是linux默认情况下并没有开通,可以通过指令打开
    route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
    
    • 如果需要服务器启动时即开通组播需在/etc/sysconfig/static-routes文件内加入eht0 net 224.0.0.0 netmask 240.0.0.0

    • 然后检查多播端口是否在您的 UDP 开放列表中,并且接收方 TCP 端口也为两台机器打开!

标签:多播,tomcat,--,0.0,会话,session
From: https://www.cnblogs.com/novice77/p/16555029.html

相关文章

  • session和cookie
    constKoa=require('koa')constrouter=require('koa-router')()constviews=require('koa-views')constnunjucks=require('nunjucks')constsession=requ......
  • IDEA 配置tomcat的输出数据格式为UTF-8
    之前学SpringMVC获取前端页面传过来的数据在控制台打印会出现中文乱码,后面发现这个其实是Tomcat的配置问题。  以IDEA为例,在tomcat中配置  配置参数 -Dfile.en......
  • windows使用/服务(3)windows11 部署tomcat图文教程
    参考地址:https://zhuanlan.zhihu.com/p/874392681、下载JDK安装包,下载地址:下载JDK安装包,已安装jdk忽略Java18oracle-jdk官网:https://www.oracle.com/java/techno......
  • 无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态
    问题:无法向会话状态服务器发出会话状态请求。请确保ASP.NETStateService(ASP.NET状态服务)已启动,并且客户端端口与服务器端口相同。如果服务器位于远程计算机上,请检......
  • Tomcat静态文件访问配置
    tomcat访问服务器资源修改server.xml文件添加<Hostname="localhost"appBase="webapps"unpackWARs="true"autoDeploy="true"><!--Single......
  • 在IDEA中配置tomcat
    目录在IDEA中配置tomcat在IDEA中配置tomcat本篇演示的只是IDEA中配置tomcat并没有演示用tomcat进行项目部署,以及更多关于tomcat的介绍,这些内容在下一阶段我都会......
  • tomcat自定义错误页面
    tomcat自定义错误页面 当我们访问tomcat的一个不存在的页面,返回错误信息如下: 这样的界面直接暴露给用户并不友好,有时候还不安全,因此一般需要修改默认的错误......
  • Tomcat AJP ghostcat (CVE-2020-1938) 图解分析
    上周扫描到一个TomcatAJP,无法利用。具体扫描方法是设置自定义属性。但是目标机器删掉了ROOT文件夹也没有设置context。所以研究一下TomcatAJP,顺带看看Tomcat源码,找......
  • idea调试tomcat源码
    优化TomcatAJP误报时有一些疑问,调试一下1下载tomcat历史版本列表:https://archive.apache.org/dist/tomcat/tomcat-8/源码文件夹:https://archive.apache.org/dist/t......
  • 修改Tomcat启动窗口的名称
    打开Tomcat的bin目录下的Catalina.bat,找到这一属性块:doStartshiftif"%TITLE%"==""setTITLE=projecNameset_EXECJAVA=start"%TITLE%"%_RUNJAVA%ifnot""%1"......