Apache 2.2.11 + (proxy_ajp, proxy_balancer) + Tomcat 5.5.27 + Terracotta 2.7.2
어제 오늘 열라 삽질한 결과물 입니다.
상용와스 사용하며 개발만 하다보니...
아파치 톰켓 제대로 세팅할 일도 없었고...
Load balancing 할 일은 더욱이 없었고..
Sessions Clustering 할 일은 더더욱 없었는데...
이번에 고객이 와스를 구입 하지 않는 데다..
사이트 두개의 세션을 공유시켜 달라고 해서...
이참에 한 번 세팅해보자 해서.. 시도해봤습니다...
짧은 실력에 더 짧은 영어 실력까지 함께하다 보니...
삽질의 연속.. -_-;;
삽질 해서 돌아가게는 했는데...
저도 이해하고 한게 아니라서... 뭐라 설명 드리긴 뭐 하구요...
혹시 필요하신 분들 있으실까봐...
올려 봅니다...
나~ 중에 어느분이 더 나은 세팅법을 공유해 주시길 바라며.. 이만.. ^^;;
=========================== 설치파일 ===========================
jdk-1_5_0_17-windows-i586-p.exe
apache_2.2.11-win32-x86-no_ssl.msi
apache-tomcat-5.5.27.zip
terracotta-generic-2.7.2.tar.gz
=========================== 설치 디렉토리 ===========================
C:\Program Files\Java\jdk1.5.0_17
D:\test\Apache2.2
D:\test\apache-tomcat-5.5.27
D:\test\terracotta-2.7.2
=========================== System Path 설정 ===========================
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_17
TC_INSTALL_DIR=D:\test\terracotta-2.7.2
CATALINA_HOME=D:\test\apache-tomcat-5.5.27
=========================== 호스트파일에 추가 ===========================
C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1 server1.example.com
127.0.0.1 server2.example.com
=========================== 아파치 설정 ===========================
D:\test\Apache2.2\conf\httpd.conf
# LoadModule -- 주석을 푼다.
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule rewrite_module modules/mod_rewrite.so
# Virtual hosts -- 주석을 푼다.
Include conf/extra/httpd-vhosts.conf
=========================== 아파치 가상호스트 설정 ===========================
D:\test\Apache2.2\conf\extra\httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin server1@example.com
ServerName server1.example.com
ServerAlias server2.example.com
ErrorLog "logs/server1.example.com-error.log"
CustomLog "logs/server1.example.com-access.log" common
DocumentRoot "D:/test/sample/WebContent"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Location /*>
ProxyPass balancer://tomcat_cluster stickysession=JSESSIONID
</Location>
## mod_proxy_balancer
## 필요한 만큼 BalancerMember를 추가하면 자동으로 분산 요청
## 아래 주소는 단지 예시일 뿐
##
<Proxy balancer://tomcat_cluster>
BalancerMember ajp://127.0.0.1:9071 route=tomcat1 loadfactor=50
BalancerMember ajp://127.0.0.1:9072 route=tomcat2 loadfactor=50
</Proxy>
<Directory "D:/test/sample/WebContent">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
## jsp 파일도 index 파일로 추가
##
DirectoryIndex index.html index.jsp
## Rewrite를 이용해서 jsp 파일을 proxy_ajp로 Tomcat으로 넘기기
##
RewriteEngine On
RewriteCond %{REQUEST_URI} /servlet* [OR]
RewriteCond %{REQUEST_FILENAME} .jsp
RewriteRule (.*) balancer://tomcat_cluster/$1 [P]
</Directory>
</VirtualHost>
=========================== 테라코타 설정파일 수정 ===========================
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5\tc-config.xml
server host 에 테라코타 서버가 설치된 아이피 입력
...
<servers>
<server host="127.0.0.1" name="sample">
<data>data/server-data</data>
<logs>logs/server-logs</logs>
</server>
<update-check>
<enabled>true</enabled>
</update-check>
</servers>
...
...
<web-applications>
<web-application>ROOT</web-application>
<!--
<web-application>Cart</web-application>
<web-application>DepartmentTaskList</web-application>
<web-application>Townsend</web-application>
-->
</web-applications>
...
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5\start.bat
세션을 공유할 도메인 입력(server1.example.com 과 server2.example.com 이 세션을 공유해야 하는 경우에만 필요함)
...
set OPTS=%TC_JAVA_OPTS% -Dwebserver.log.name=tomcat-%1
set OPTS=%OPTS% -Dcom.sun.management.jmxremote
set OPTS=%OPTS% -Dproject.name=Configurator
set OPTS=%OPTS% -Dcom.tc.session.cookie.domain=.example.com
set JAVA_OPTS=%OPTS% %JAVA_OPTS%
...
=========================== 톰켓 server.xml 수정 ===========================
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5\9081\conf\server.xml
<Server port="9051" shutdown="SHUTDOWN">
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="9081" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="9071"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" reloadable="true" docBase="D:\test\sample\WebContent" workDir="work" />
</Host>
</Engine>
</Service>
</Server>
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5\9082\conf\server.xml
<Server port="9052" shutdown="SHUTDOWN">
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="9082" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="9072"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" reloadable="true" docBase="D:\test\sample\WebContent" workDir="work" />
</Host>
</Engine>
</Service>
</Server>
=========================== 셈플소스 복사 ===========================
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5\9081\webapps\Cart
하위의 소스를 아래 디렉토리로 복사
D:\test\sample\WebContent
=========================== 테라코타 서버 실행 ===========================
D:\test\terracotta-2.7.2\bin>start-tc-server.bat
=========================== 아파치 서버 실행 ===========================
Apache Service Monitor [start] 버튼 클릭
=========================== 톰켓 서버(테라코타 클라이언트) 실행 ===========================
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5>start.bat 9081
D:\test\terracotta-2.7.2\tools\sessions\configurator-sandbox\tomcat5.5>start.bat 9082
=========================== 잘 돌아가는가 확인 ===========================
http://server1.example.com/carts.jsp
http://server2.example.com/carts.jsp
=========================== 끝!!! ===========================
참고 사이트들....
http://www.javaservice.net/~java/bbs/read.cgi?m=&b=qna2&c=r_p&n=1224247277&p=7&s=d
http://www.ibm.com/developerworks/kr/library/opendw/20071231/
http://wiki.kldp.org/wiki.php/Apache2Tomcat5Howto2
http://www.okjsp.pe.kr/seq/130244
http://www-128.ibm.com/developerworks/kr/library/opendw/20061017/#main
http://sakuragis.egloos.com/4590029
http://hmjkor.tistory.com/tag/Apache2
http://forcemax.tistory.com/69
외 다수~~~~~~~~