오픈소스/Apache + Tomcat

[Apache+ Tomcat] TCP를 통한 톰캣 세션클러스터링(클라우드 환경)

728x90
반응형

Apache 작업

1) workers_jk.properties 수정

worker.list=load_balancer
worker.load_balancer.type=lb
worker.load_balancer.balance_workers=was_01,was_02
worker.load_balancer.sticky_session=true

#was1
worker.was_01.type=ajp13
worker.was_01.host=IP
worker.was_01.port=8090
worker.was_01.lbfactor=5

#was2
worker.was_02.type=ajp13
worker.was_02.host=IP
worker.was_02.port=8090
worker.was_02.lbfactor=1

 

2) httpd-vhosts.conf 수정

 <VirtualHost *:80>
      DocumentRoot "/data/apache2.4/htdocs"
      ServerName test.com
      CustomLog "|/data/apache2.4/bin/rotatelogs /data/apache2.4/logs/access_%Y_%m_%d.log 86400 +540" common env=!exceptlist
      JkMount /* load_balancer
 
      Header set Access-Control-Allow-Origin "*"
      Header set Content-Security-Policy "default-src 'unsafe-inline' 'unsafe-eval' * data: ;"
  </VirtualHost>

 

 

 

 

Tomcat 작업

1) server.xml 수정

<Engine name="Catalina" defaultHost="localhost" > 지우고 아래부터 삽입

 

#was1 server.xml

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

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

<!-- was server1 information-->
<Receiver     
      address="was1_IP"       
      autoBind="0"    
      className="org.apache.catalina.tribes.transport.nio.NioReceiver"
      maxThreads="6"     
      port="4001"     
      selectorTimeout="5000"

/> 

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

 <!-- was server2 information-->
  <Member 
         className="org.apache.catalina.tribes.membership.StaticMember"    
          port="4001"
          host="was2_IP"
          uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}" 
  />
   
</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;"
/>

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

 

 

#was2 server.xml

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

  <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>
         
  <!-- was server2 information-->
          <Receiver
                  address="was2_IP" 
                  autoBind="0"
                  className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  maxThreads="6"
                  port="4001"
        />

/> 
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">
 
 <!-- was server1 information-->
 <Member
         className="org.apache.catalina.tribes.membership.StaticMember"    
          port="4001"
          host="was1_IP"
          uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}"  />

</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;"
/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

 

 

*설명

port: tomcat 여러대 간의 세션 공유할 port 지정 (방화벽 Open해줘야함 )
uniqueId: tomcat의 고유 ID 

728x90
728x90