- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
Tomcat Clustering 본문
|
http://www.easywayserver.com/implementation-tomcat-clustering.htm
위 문서에 정말 잘 나와 있다.
나는 하나의 서버 안에 Apache Server와 TomcatA Server와 TomcatB Server 가 같이 있는, Vertical Clustering 을 구현했다.
위 페이지에 나와 있는 대로 Tomcat 서버의 server.xml 파일을 설정했다.
httpd-jk.conf 파일과 workers.properties 파일의 설정은 이 웹페이지의 아래에 적어 두었다.
이렇게 Clustering을 하는 이유는 Fail Over 시에 대비하고, 웹 어플리케이션 변경 시에도 중단 없는 서비스를 제공하기 위함이다. 이렇게 하기 위해서는 Tomcat Server 앞 단에 Apache Server 를 두어야 한다.
설치일: 2015-02-05
OS: Ubuntu 12.04
위 페이지에 있는 대로
b) Apache2 설치
#sudo apt-get install apache2
설치 완료 후, 'http://서버IP' 입력시 It works 페이지 정상출력
< 실제 경로 : /var/www (web root directory) >
d) Mod_jk 설치
#sudo apt-get install libapache2-mod-jk
http://www.easywayserver.com/implementation-tomcat-clustering.htm 문서에 보면
httpd.conf 를 편집하라고 되어 있는데,
/etc/libapache2-mod-jk/httpd-jk.conf
이 파일을 편집하면 된다.
/etc/libapache2-mod-jk/workers.properties
이 파일을 열어서 위 웹페이지에 있는대로 수정함.
위와 같은 로그.
<VirtualHost *:80>
JkMount /* loadbalancer
JkMount /jk-manager/* jk-manager
JkMount /jk-status/* jk-status
</VirtualHost>
test.jsp 파일을 각각 tomcatA 와 tomcatB 에 넣고, 실행해 봤더니
Fail Over 시 다른 tomcat 서버로 연결은 잘 되는데, 세션 ID가 달라짐.
Serializable 을 상속받은 객체를 세션에 저장해 봤는데, 세션 복제가 안됨.
[문제 해결]
web.xml 파일에 <distributable /> 을 넣지 않았었음. 넣으니까 Session ID가 동일하게 생기고, 세션이 복제됨.
이렇게 하지 않으면 웹브라우저에서 tomcatA 에 접근하고 나서 tomcatB에 접근하면 Sessino ID가 바뀜. 그 반대의 경우도 마찬가지.
web.xml 파일에 <distributable /> 을 넣으면
tomcatA로 접근할 때: 6A3BC293E869AE55712BA00D86FCD255.tomcatA
tomcatB로 접근할 때: 6A3BC293E869AE55712BA00D86FCD255.tomcatB
세션에 저장한 값이 tomcatA, tomcatB 서버에서 서로 공유됨.
JK Status Manager 셋팅
[참고]
http://www.celinio.net/techblog/?p=1095
http://www.gesea.de/techdocs.htm?id=67616
/etc/libapache2-mod-jk/httpd-jk.conf
<IfModule jk_module> # We need a workers file exactly once # and in the global server JkWorkersFile /etc/libapache2-mod-jk/workers.properties # Our JK error log # You can (and should) use rotatelogs here JkLogFile /var/log/apache2/mod_jk.log # Our JK log level (trace,debug,info,warn,error) JkLogLevel info # Our JK shared memory file JkShmFile /var/log/apache2/jk-runtime-status # Start a separate thread for internal tasks like # idle connection probing, connection pool resizing # and load value decay. # Run these tasks every JkWatchdogInterval seconds. # Since: 1.2.27 JkWatchdogInterval 60 # Configure access to jk-status and jk-manager # If you want to make this available in a virtual host, # either move this block into the virtual host # or copy it logically there by including "JkMountCopy On" # in the virtual host. # Add an appropriate authentication method here! <Location /jk-status> # Inside Location we can omit the URL in JkMount JkMount jk-status Order deny,allow Deny from all Allow from 127.0.0.1 </Location> <Location /jk-manager> # Inside Location we can omit the URL in JkMount JkMount jk-manager Order deny,allow Deny from all Allow from 127.0.0.1 Allow from 61.**.208.*** </Location> # Example for Mounting a context to the worker "balancer" # The URL syntax "a|b" instantiates two mounts at once, # the first one is "a", the second one is "ab". # JkMount /myapp|/* balancer <VirtualHost *:80> JkMount /* loadbalancer JkMount /jk-manager|/* jk-manager JkMount /jk-status|/* jk-status </VirtualHost> </IfModule>
/etc/libapache2-mod-jk/workers.properties
# workers.properties - workers.tomcat_home=/home/test-user/tomcatA workers.java_home=/usr/lib/jvm/default-java ps=/ worker.list=loadbalancer,jk-status,jk-manager worker.jk-status.type=status worker.jk-manager.type=status worker.tomcatA.port=8109 worker.tomcatA.host=localhost worker.tomcatA.type=ajp13 worker.tomcatB.port=8209 worker.tomcatB.host=localhost worker.tomcatB.type=ajp13 # # Specifies the load balance factor when used with # a load balancing worker. # Note: # ----> lbfactor must be > 0 # ----> Low lbfactor means less work done by the worker. worker.tomcatA.lbfactor=1 worker.tomcatB.lbfactor=1 worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=tomcatA,tomcatB worker.loadbalancer.sticky_session=1
test.jsp
<% String user = request.getParameter("user"); String savedUser = (String)session.getAttribute("user"); if( user != null && !user.isEmpty() ) { session.setAttribute("user",user); } %> <html> <head> <title>Test JSP</title> </head> <body> <form action="/examples/test.jsp" name="frm"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#CCCCCC"> <td width="20%">TomcatB Machine</td> <td width="80%"> </td> </tr> <tr> <td>Session ID :</td> <td><%=session.getId()%></td> </tr> <tr> <td>Saved User :</td> <td><input type="text" value="<%=savedUser%>" /></td> </tr> <tr> <td>New User :</td> <td><input type="text" name="user" value="" /></td> </tr> <tr> <td colspan="2"><input type="button" value="SEND" onclick="frm.submit()" /></td> </tr> </table> </form> </body> </html>
< 테스트 방법 >
1) Apache Web Server 로 접속 (80포트)
2) 세션에 저장할 User 이름을 입력하고 SEND 버튼을 누른다.
3) 주소줄에서 test.jsp 뒤의 파라미터를 지우고 엔터를 누른다.
4) 세션에 저장된 User 값이 보인다.
5) Tomcat B 서버를 죽이고, 새로고침 했을 때, 세션에 저장된 User 이름이 동일하게 보이고, Session ID도 동일하고, Session ID 뒤의 jvmRoute 값만 tomcatA 로 변경됨을 확인한다. ( TomcatA 서버로 연결되고, 세션에 저장된 값도 그대로 복제되었음을 확인할 수 있다.) jvmRoute 값은 tomcat 의 server.xml 안에서 설정한 값이다.
Tomcat Session Cluster 에 대하여 (1)
Tomcat Clustering Series Part 1 : Simple Load Balancer
http://www.javacodegeeks.com/2012/11/tomcat-clustering-series-part-1-simple-load-balancer.html
Running Multiple Tomcat Instances on Single Machine
http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html
[Apache - Tomcat] 로드 밸런싱, 세션 클러스터링
Apache 2.2 로드 밸런싱 Tomcat 6.0 세션 클러스터링
[ tomcat ] loadbalacing 과 session clustering
http://shonm.tistory.com/entry/tomcat-loadbalacing-%EA%B3%BC-session-clustering
An Introduction To Tomcat Cluster Configuration
http://www.mulesoft.com/tcat/tomcat-cluster
Tomcat Clustering - A Step By Step Guide
Tomcat Clustering - Fail Over
Tomcat Clustering 으로 묶으면 Fail Over 가 적용될까?
http://stackoverflow.com/questions/11465714/tomcat-webapp-failover
http://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html
* failover 로 검색해 볼 것.
http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html#Bind_session_after_crash_to_failover_node
'Java' 카테고리의 다른 글
poi 라이브러리로 Excel File Spread Sheet Cell 읽기 (0) | 2015.03.31 |
---|---|
AspectJ 버그 해결 (0) | 2015.03.25 |
상속 대신 Composition 으로 다른 객체의 기능 사용하는 예제 (0) | 2015.01.07 |
Interface로 다중상속을 대체할 수 있음을 보여주는 예제 (1) | 2015.01.07 |
log 내용을 DB에 저장하기 (1) | 2014.12.17 |