요구사항: AP1은 상시 Active 상태 이고, AP1이 문제 생기거나 패치시 AP2가 백업으로 활성화 되도록 조치 |
nginx.conf 에서 upstream의 특정 server에 backup 만 추가해줌
http {
...(생략)...
upstream tomcatGroup{
server 127.0.0.1:8090 max_fails=3 fail_timeout=3s;
server 127.0.0.1:8094 backup; //backup 추가
}
server {
listen 80;
listen [::]:80;
...(생략)...
location / {
proxy_pass http://tomcatGroup;
...(생략)...
}
} //end - server
} //end - http
테스트 결과, AP1(Main) 이 다운되면 , AP2(Backup)으로 세션 전달됨
AP1이 재구동 시작되면, AP2의 연결이 끊기고 AP1이 완전히 구동될 때까지 대기 상태로 됨.
[참고] tomcat 클러스터링
AP1에서 AP2로 세션이 유지하기 위해서는 각 tomcat server.xml 및 web.xml에서 아래 설정 추가해야 함
https://tomcat.apache.org/tomcat-8.0-doc/cluster-howto.html
Apache Tomcat 8 (8.0.53) - 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 the session gets replicated to all the other no
tomcat.apache.org
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
...(생략)...
<Service name="Catalina">
...(생략)...
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="60000"
URIEncoding="UTF-8"
enableLookups="false"
redirectPort="443"
disableUploadTimeout="true"
maxThreads="500"
minSpareThreads="100"
maxSpareThreads="300"
maxConnection="8192"
maxParameterCount="1000000"
compression="on"
compressionMinSize="204800"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/plain,text/xml,text/css,text/javascript,application/javascript,application/json,application/octet-stream"
useSendfile="false" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat8090">
//방법 1.
//아래 <Cluster> 태그만 주석 해제해도 동작함
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
//방법 2.
//아래 <Cluster> 태그는 관련 옵션 customize 할 때 사용
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<!-- <Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/> -->
<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"
//[중요] TCP port 4000~ 4100 설정가능
//같은 서버에서 tomcat이 여러개일 경우 해당 포트 각각 다르게 설정
port="4001"
selectorTimeout="100"
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"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/>
<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> -->
...(생략)...
</Engine>
</Service>
</Server>
F12 - Application - Storage(Cookies)에서 JSESSIONID 확인
AP1 강제 종료하면 tomcat 로그에
정보 [Membership-MemberDisappered.] 멤버 사라짐 메시지를 수신했습니다. 로그 확인
F12 - Application - Storage(Cookies)에서 JSESSIONID 다시 확인해보면 AP2 의 jvmRoute 값(tomcat8094)으로 변경된 것을 확인할 수 있음.
'server > nginx' 카테고리의 다른 글
[nginx- tomcat] 세션 클러스터링 (0) | 2021.08.19 |
---|