본문 바로가기
TOMCAT/사이트 여러개 운영

[ TOMCAT ] Clustering 설정 ( without broadcasting )

by 정윤재 2021. 1. 31.

클라우드 시스템이나 특별한 사정에 의해 broadcating 을 사용한 session clustering 을

못하는 경우가 있습니다.

그런 경우를 위해 개개의 클러스터링 대상 서버의 IP, PORT 를 사용하여 연결 하는 

설정을 해보겠습니다.

 

준비 사항 : JAVA 8

               TOMCAT8.5 3개 (저는 편의상 같은 서버에 TOMCAT 3개를 설치했음)

               

참고 사항 : 원래 톰캣 공식 사이트에서는 개별 서버에서 session 데이터를 공유하는 member port 를

               4000 ~ 4100 으로 할 것을 추천하지만 전 3100,3200,3300 으로 설정하였음

 

1. 1번 TOMCAT 의 conf/server.xml 설정 (<Engine> 태그 밑에 아와 같이 설정 한다.)

나머지 2번 서버, 3번 서버 설정은 바로 사용할 수 있게 첨부 파일로 첨부 하겠습니다.

1번 서버 내용에서 빨간색 글씨 부분만 변경 되는 것입니다. (설정이 거의 같기 때문에 생략합니다.)

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

<Cluster 
        channelSendOptions="8" 
        channelStartOptions="3" 
        className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
    <Manager 
        className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"
    />
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.122.1" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="3100" 
            selectorTimeout="5000"
        /> <!-- server1 information -->
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3200" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}" 
            /> <!-- server2 -->
			<Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3300" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3}" 
            /> <!-- server3 -->
        </Interceptor>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor" />
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
    />
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

 

2번 TOMCAT 의 conf/server.xml 설정

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

<Cluster 
        channelSendOptions="8" 
        channelStartOptions="3" 
        className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
    <Manager 
        className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"
    />
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.122.1" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="3200" 
            selectorTimeout="5000"
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3100" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}" 
            /> <!-- server1 -->
			<Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3300" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3}" 
            /> <!-- server3 -->
        </Interceptor>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor" />
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
    />
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

3번 TOMCAT 의 conf/server.xml 설정

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat3">
<Cluster 
        channelSendOptions="8" 
        channelStartOptions="3" 
        className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
		<!--
		channelSendOptions="8" : async
		channelSendOptions="2" : use_ack
		channelSendOptions="6" : sync,use_ack
		
		channelStartOptions 에 대한 설명은 공식 사이트에서는
		To start a channel without multicasting, you would want to use the value Channel.SND_RX_SEQ | Channel.SND_TX_SEQ that equals to 3.
		와 같이 나온다. 대략 해석 하면 multicat 를 사용하지 않으려면 3을 설정 하란 내용
		-->
    <Manager 
        className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"
    />
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.122.1" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="3300" 
            selectorTimeout="5000"
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3100" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}" 
            /> <!-- server1 -->
			<Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="3200" 
                host="192.168.122.1" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}" 
            /> <!-- server2 -->
        </Interceptor>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor" />
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
    />
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

server.xml_server1
0.01MB
server.xml_server2
0.01MB
server.xml_server3
0.01MB

 

2. web.xml 의 태그 추가

web.xml 파일에서

</web-app> 태그 위에 
<distributable/> 태그를 추가 합니다.

 

* 주의 사항

IP 나 host 가 다를 경우 앞단에서 web server (apache, nginx) 등으로 domain 설정 등이 필요함
이유는 session 이라는게 cookie 를 이용하기 때문에 동일 도메인으로 들어오지 않으면 

session clustering 으로 안될 수 있음

 

* 테스트 방법

http://shonm.tistory.com/642

'TOMCAT > 사이트 여러개 운영' 카테고리의 다른 글

[ TOMCAT ] Clustering test (테스트)  (0) 2021.02.01
Tomcat 6.0 사이트 여러개 운영  (0) 2010.04.05

댓글