HD

session clustering 적용 (feat.Tomcat7 이상) 본문

WAS/Tomcat

session clustering 적용 (feat.Tomcat7 이상)

hunecenter 2020. 10. 5. 16:10
반응형

이번 프로젝트를 하면서 session clustering 적용하면서 내용을 정리...

-tomcat jvmRoute설정

session clustering을 설정한다는건 apache기준 workers.properties를 설정을 해줬을것이다.

 jvmRoute에 지정한 worker 명을 넣어주면 된다.

빨간색 부분은 중복되지 않은 공유의 톰캣을 구분 값

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker3_22">

아래 이미지 처럼 JSESSIONID에 .worker3_22로 tomcat을 구분할수 있다.

 

 

- WEB-INF/web.xml (distributable 태그 추가)

<!-- web.xml -->
<distributable/>

- tomcat server.xml (tomcat8 기준)

  1. multicast 방식으로 동작하며 address는 ‘228.0.0.4’, port는 ‘45564’를 사용하고 서버 IP는 java.net.InetAddress.getLocalHost().getHostAddress()로 얻어진 IP 값으로 송출됩니다.
  2. 먼저 구동되는 서버부터 4000 ~ 4100 사이의 TCP port를 통해 reqplication message를 listening합니다.
  3. Listener는 ClusterSessionListener, interceptor는 TcpFailureDetector와 MessageDispatchInterceptor가 설정됩니다.

※ 각 다른 서버에 적용할땐 <Membership> port="45564" <Receiver> port="4000"을 다르게 해야한다.

   ex)<Membership> port="45565" <Receiver> port="4001"

<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.0.0.4"
                    port="45564"
                    frequency="500"
                    dropTime="3000"/>
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="auto"
                  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"/>

    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/tmp/war-temp/"
            deployDir="/tmp/war-deploy/"
            watchDir="/tmp/war-listen/"
            watchEnabled="false"/>

    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

 

※참고 tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html

 

Apache Tomcat 8 (8.5.58) - Clustering/Session Replication How-To

Simply add to your or your element to enable clustering. Using the above configuration will enable all-to-all session replication using the DeltaManager to replicate session deltas. By all-to-all, we mean that every session gets replicated to all the other

tomcat.apache.org

- tomcat server.xml (tomcat7 기준)

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
	<Manager className="org.apache.catalina.ha.session.BackupManager"
		expireSessionsOnShutdown="false"
		notifyListenersOnReplication="true"/>

	<Channel className="org.apache.catalina.tribes.group.GroupChannel">
		<Membership className="org.apache.catalina.tribes.membership.McastService"
			address="228.0.0.4"
			port="45564"
			frequency="500"
			dropTime="3000"/>

		<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
			<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
		</Sender>

		<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
			address="auto"
			port="4000"  
			autoBind="100"
			selectorTimeout="5000"
			maxThreads="6"/>

		<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
		<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

	</Channel>

	<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
	<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

	<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
			tempDir="/tmp/war-temp/"
			deployDir="/tmp/war-deploy/"
			watchDir="/tmp/war-listen/"
			watchEnabled="false"/>

	<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
	<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

※참고 tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html

 

Apache Tomcat 7 (7.0.106) - Clustering/Session Replication HOW-TO

To make it easy to understand how clustering works, we are gonna to take you through a series of scenarios. In this scenario we only plan to use two tomcat instances TomcatA and TomcatB. We will cover the following sequence of events: TomcatA starts up Tom

tomcat.apache.org

 

 

반응형

'WAS > Tomcat' 카테고리의 다른 글

Tomcat Server.xml 암호화 (feat.AES)  (0) 2022.06.23
리눅스 톰켓 한글 깨짐 현상 해결  (0) 2022.03.08
TOMCAT 버전업 문제  (0) 2020.08.04
Tomcat JDK변경  (0) 2020.07.13
Tomcat ORACLE JNDI Datasource 설정  (0) 2019.01.23
Comments