<!-- 此最佳优化配置仅供参考 --> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="800" minSpareThreads="100"/> <Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" connectionTimeout="60000" redirectPort="8443" enableLookups="false" maxPostSize="-1" URIEncoding="UTF-8" acceptCount="1000" disableUploadTimeout="true" maxConnections="10000" SSLEnabled="false"/>
2. 修改 TOMCAT_BASE/webapps/ROOT/index.jsp
,添加:
<table align="center" border="1"> <tr> <td>cluster-desc</td> <!-- 分别修改描述 --> <td>This is the first tomcat</td> <td>This is the second tomcat</td> </tr> <tr> <td>SessionID</td> <td><%= request.getSession().getId() %></td> </tr> <tr> <td>SessionCreatedTime</td> <td><%= request.getSession().getCreationTime() %></td> </tr> <tr> <td>ServerName</td> <td><%=request.getServerName()%></td> </tr> <tr> <td>SessionPort</td> <td><%=request.getServerPort()%></td> </tr> </table>
upstream ha-balance { server 127.0.0.1:8080 weight=1; server 127.0.0.1:8081 weight=1; } location = / { proxy_pass http://ha-balance; }
4. 测试,访问:http://127.0.0.1
发现每次的sessionId都是不一样的
Add session manager
tomcat/conf/server.xml
in GlobalNamingResources
tag area:<GlobalNamingResources> <Resource name="bean/redisson" auth="Container" factory="org.redisson.JndiRedissonFactory" configPath="${catalina.base}/conf/redisson.yaml" closeMethod="shutdown"/> </GlobalNamingResources>
tomcat/conf/context.xml
in Context
tag area:<Context> <ResourceLink name="bean/redisson" global="bean/redisson" type="org.redisson.api.RedissonClient" /> <Manager className="org.redisson.tomcat.JndiRedissonSessionManager" readMode="REDIS" jndiName="bean/redisson" /> </Context>
tomcat/conf/redisson.yaml
更多配置可以参考 https://github.com/redisson/redisson/wiki/2.-ConfigurationsingleServerConfig: idleConnectionTimeout: 10000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 password: null subscriptionsPerConnection: 5 clientName: null address: "redis://127.0.0.1:6379" subscriptionConnectionMinimumIdleSize: 1 subscriptionConnectionPoolSize: 50 connectionMinimumIdleSize: 24 connectionPoolSize: 64 database: 0 dnsMonitoringInterval: 5000 threads: 16 nettyThreads: 32 codec: !<org.redisson.codec.MarshallingCodec> {} transportMode: "NIO"
Copy two jars into
TOMCAT_BASE/lib
directory:
重启tomcat,session共享测试,访问:
http://127.0.0.1/
发现每次的sessionId都是一样的