ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 톰캣 세션 클러스터링
    개발자 이야기 2020. 6. 15. 13:43

    아파치 1개와 두 개의 톰캣으로 로드 밸런싱을 구성하였다.
    브라우저에서 새로고침을 할 때마다 각각의 WAS에서 로그가 올라오는 것을 보니 정상적으로 동작하는 것 같다.
    문제는 로그인을 하자마자 바로 나타났다.
    로그인 후에는 로그인 성공 페이지로 리다이렉트를 시키는데, 다른 WAS로 리다이렉트가 되니 오류가 발생했다.
    두 개의 톰캣이 로그인 세션을 서로 공유하지 않아 생기는 오류였다.
    그래서 두 개의 톰캣이 하나의 세션을 공유할 수 있도록 세션 클러스터링이 필요하다.

    세션 클러스터링 구성 방법은 구글을 찾아 보니 많이 나오기도 했고 쉬웠다.

     

    web.xml에 아래를 추가하고,

    <distributable/>

    server.xml에 아래를 추가한 후 약간의 설정만 해주면 된다.

    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                     channelSendOptions="8">
    
              <Manager className="org.apache.catalina.ha.session.DeltaManager"
                       expireSessionsOnShutdown="false"
                       notifyListenersOnReplication="true"/>
    			
    			<!-- 멀티캐스트 포트(45564) 필요에 따라 변경 -->
              <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"/>
    			<!-- replication 메시지 수신 포트는 4000 - 4100 사이 -->
                <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.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.ClusterSessionListener"/>
            </Cluster>

    그런데 오류가 발생했다.

    java.lang.ClassNotFoundException: org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor

    구글에 검색해 보니 의외로 위 관련된 내용이 별로 없었다.
    가끔 중국어로 된 내용이 있었으나 읽지 못하니 무시버렸고, 계속 검색만 했다.

    점심먹고 와서 다시 검색해보고 결과가 나오지 않자, 중국어로 된 검색결과를 번역기를 통해 내용을 확인했다.

    답은 쉽게 나왔다.

    MessageDispatch15Interceptor가 없으니 MessageDispatchInterceptor를 사용하라는 얘기였다.

    수정 후 서버를 재기동하니 다른 문제가 발생했다.
    살짝 화가 났다.

    MessageDispatch15Interceptor를 쓰라고 해놓고 왜 MessageDispatchInterceptor로 바꾸라고 얘기했을까?
    혹시 톰캣 버전에 따라 설정방법이 다른 건 아닐까?

    그래서 톰캣 사이트에 들어가서 문서를 찾았다.

     

    tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html

     

    Apache Tomcat 8 (8.5.56) - 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

    위 설정대로 하니 잘 되었다.
    설정 방법이 톰캣의 버전마다 조금씩 달랐었나 보다. 나는 8.5를 쓰고 있었고...

    생각해보니 나도 나의 행동에 실망감을 감출 수 없었다.
    처음부터 톰캣 사이트에 들어가서 검색해보면 되었을 것을 굳이 구글로 검색하겠다고 오전을 다 소비해버렸으니 말이다.
    오늘을 조금 반성해 본다.

     

    아래는 http://tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html 의 내용이다.

    <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>

    '개발자 이야기' 카테고리의 다른 글

    톰캣 세션 클러스터링  (0) 2020.06.15
    춘천 간 김에 화천, 철원 들리다.  (0) 2018.12.14
    가족앨범 만들기  (0) 2018.08.26
    수다쟁이  (0) 2018.07.26
    야근식대  (0) 2018.04.24
    마음가짐  (0) 2017.12.07

    댓글 0

Designed by Tistory.