본문 바로가기

WEB & WAS/Tomcat

[Tomcat] Clustering(클러스터링)

반응형

개요

WAS의 성능향상 및 서비스 연속성을 위한 목적으로 클러스터를 많이 구성합니다. WAS의 제품군은 별도의 L4 장비를 이용하지 않고도 자체기능에서 세션 공유기능을 제공하여 한쪽이 장애가 생기더라도 원할한 서비스가 가능하도록 설계되어져 있습니다. 다음은 웹서버(apache)와 WAS(톰캣)을 이용하여 세션클러스터링을 구성한 예입니다.

 

아래 내용은 톰캣과 아파치가 연동이 되어 있다는 전제하에 설명합니다.

톰캣 아파치 연동은 아래 참조

https://fliedcat.tistory.com/2?category=724321

 

[그림 1] 톰캣 클러스터 구성

Tomcat 구성

1. server.xml 수정

  1.1 심플 클러스터 설정

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

위 부분의 주석 처리가 되어있다면 주석 제거

  1.2 상세 클러스터 설정

<Engine> 또는 <Host> 절에 아래 내용 추가

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

- Membershipe 절에 address=228.0.0.4", port=45564" 두요소는 클러스터멤버쉽을 구성(동일 클러스터는 동일 address,port를 가져야함)

- 동일 서버에 여러개의 톰캣을 설치하여 클러스터멤버쉽을 구성할경우 Receiver 절의 port 변경

 

1.3 각 JSESSION_ID의 끝에 tag를 붙이고자 한다면 jvmRoute 요소를 추가합니다.(옵션)

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

예) 5364B126FE79474FE1CA714D4D104825.tomcat1

 

2. 세션을 공유하고자 하는 웹어플리케이션의 web.xml에 <distributable/> 요소 추가

예)WEB-INF/web.xml

<web-app> .....

  <distributable/>

</web-app>

3. TroubleShooting

증상 : Catalina.out 파일에 아래와 같은 오류가 발생

org.apache.catalina.ha.tcp.SimpleTcpCluster.startInternal Unable to start cluster. org.apache.catalina.tribes.ChannelException: java.net.SocketException: No such device; No faulty members ident

원인) 네트워크 인터페이스에서 Multicast routing이 미 작동시 발생

확인) netstat -nr 명령어로 멀티캐스트 라우팅확인( 제일 아래 224.0.0.0과 같이 되어 있다면 멀티캐스트가 작동중) 

[그림 2]멀티캐스트 라우팅 추가및 확인

조치) 멀티캐스팅 라우팅 추가

shell> route add -net 224.0.0.0 netmask 240.0.0.0 dev 인터페이스명

 

웹서버(아파치)구성

1. 연동할 Tomcat 정의

예) worker.properties

worker.list=loadbalancer  =>클러스터 멤버 그룹
worker.loadbalancer.type=lb  => 멤버 그룹의 타입지정
worker.loadbalancer.balance_workers=tomcat1,tomcat2  => 클러스터에 참여할 멤버 지정
worker.loadbalancer.sticky_session=1
worker.tomcat1.port=8009  
worker.tomcat1.host=192.168.0.120  
worker.tomcat1.type=ajp13  
worker.tomcat2.port=8009  
worker.tomcat2.host=192.168.0.121  
worker.tomcat2.type=ajp13

 

반응형

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

nginx tomcat 연동  (0) 2020.01.17
[Tomcat] Context간 세션 공유  (0) 2019.09.29
[Tomcat] WAR 파일 배포  (0) 2019.08.25
[Tomcat] Context 추가  (0) 2019.08.23
apache tomcat 연동  (0) 2019.08.23