본문 바로가기

미들웨어/Apache,Tomcat

mod_jk를 통한 Apache/Tomcat 연동 가이드

반응형

Apache와 WAS(주로 Tomcat)를 연동할 때 AJP protocol을 사용하는 mod_jk를 많이 사용한다.

 

해당 포스팅에는 mod_jk를 사용해 AJP port로 연동하는 설정방법을 정리한다.


1. 모듈 생성

 

The Apache Tomcat Connectors - Web Server HowTo (1.2.48) - Apache HTTP Server HowTo

In case you get source from subversion, ie without an existing configure script, you should have autoconf for configuration and installation. To create the mod_jk autoconf script, you will need libtool 1.5.2, automake 1.10 and autoconf 2.59 or newer. The u

tomcat.apache.org

  • 소스파일 압축 해제 후 native디렉토리로 이동해 아래와 같이 구성 및 컴파일을 진행한다.
[Apache@localhost native]$ ./configure --with-apxs=/webwas/Apache2.4/bin/apxs
...
configure: creating ./config.status


[Apache@localhost native]$ make && make install
Making all in common
...
chmod 755 /webwas/Apache2.4/modules/mod_jk.so
  • $HTTPD_HOME/modules에 mod_jk.so파일이 생성되었다.
[Apache@localhost modules]$ pwd
/webwas/Apache2.4/modules

[Apache@localhost modules]$ ls -arlt mod_jk.so
-rwxr-xr-x. 1 Apache Apache 1418592  2월 27 21:07 mod_jk.so

 

2. 생성한 모듈 load 및 관련 config파일 지정

  • 구성하는 방법은 다양하지만 개인적으로 주로 사용하는 config방식으로 가이드 하겠다.
  • httpd.conf파일에 mod-jk.conf파일을 Include하고 해당 파일에 관련 설정을 추가한다.
  • /abc/ 로 들어오는 경우를 제외한 모든 요청을 mod_jk를 사용해 Tomcat으로 전달하는 설정방법이다.
  • httpd.conf
Include conf/extra/mod-jk.conf
  • mod-jk.conf(mod_jk 모듈을 load하고 관련 설정을 추가할 JkWorkersFile을 지정한다.)
LoadModule jk_module modules/mod_jk.so

<IfModule jk_module>
    JkWorkersFile conf/extra/workers.properties
    JkLogFile /webwas/Apache24/logs/mod_jk/mod_jk.log
    JkLogLevel Info
</IfModule>
  • workers.properties
worker.list=balancer1
#######################################################################
worker.balancer1.type=lb
worker.balancer1.sticky_session=true
worker.balancer1.balance_workers=was1

worker.was1.port=8009
worker.was1.host=10.0.2.15
worker.was1.reference=worker.template
#######################################################################
worker.template.type=ajp13
worker.template.lbfactor=1
worker.template.connection_pool_timeout=60
worker.template.connection_pool_size=50
worker.template.connection_pool_minsize=30
worker.template.max_packet_size=8192
worker.template.retries=1
worker.template.reply_timeout=360000
worker.template.socket_timeout=10
worker.template.socket_connect_timeout=3000
worker.template.connect_timeout=3000
worker.template.ping_mode=A
worker.template.prepost_timeout=3000
worker.template.recovery_options=3
 

The Apache Tomcat Connectors - Reference Guide (1.2.48) - workers.properties configuration

This table lists more advanced configuration options. Most of them only apply to some types of workers. We use the abbreviations AJP for ajp13/ajp14 workers used directly via the workers.list, LB for load balancer workers, and SUB for the workers used indi

tomcat.apache.org

  • httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/webwas/Apache24/test"
    ServerName test.co.kr
    ServerAlias 127.0.0.1
    ErrorLog "|/webwas/Apache24/bin/rotatelogs /webwas/Apache24/logs/error_log.%Y%m%d 86400"
    CustomLog "|/webwas/Apache24/bin/rotatelogs /webwas/Apache24/logs/access_log.%Y%m%d 86400" combined

    JkUnMount /abc/* balancer1
    JkMount /* balancer1
</VirtualHost>

 

3. Tomcat설정

  • Apache의 mod_jk를 통해 오는 요청을 받을 수 있게 Tomcat에 AJP listener 설정을 해준다.
  • server.xml
...
  <Service name="Catalina">
    <Connector protocol="AJP/1.3"
               address="0.0.0.0"
               port="8009"
               maxThreads="100"
               minSpareThreads="100"
               secretRequired="false"
               redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="was1">
...
  • workers.properties 옵션의 port와 host정보를 확인하여 server.xml 설정을 한다.

Apache/Tomcat을 mod_jk를 사용해 연동을 하면 매우 다양한 옵션들이 존재해 환경에 맞게 튜닝이 가능한 장점이 있다.

또한 WEB/WAS사이 connection들에 대한 모니터링도 된다는 점에서 이슈에 대한 trace가 mod_proxy대비 용이하다는 장점도 존재한다.

 

결국 mod_jk로 구성할지 mod_proxy로 구성할지는 상황과 환경에 따라 달라지는 것 같다.

반응형