Tomcat Apache 연동 (mod_jk)
mod_jk 란?
: 아파치, 톰캣 연동을 위해 mod_jk라는 모듈을 사용하는데,
이는 AJP프로토콜을 사용하여 톰캣과 연동하기 위해 만들어진 모듈이다.
mod_jk는 톰캣의 일부로 배포되지만, 아파치 웹서버에 설치하여야 한다.
1)tomcat-connectors-x.x.x.tar.gz을 원하는 위치로 ftp 전송 및 압축 해제 후, 해당 경로로 이동
$ tar -zxvf apr-1.x.x.tar.gz
$ cd tomcat-connectors-1.2.48-src/native
[apache@Test1 install]$ tar -zxvf tomcat-connectors-1.2.48-src.tar.gz
tomcat-connectors-1.2.48-src/
tomcat-connectors-1.2.48-src/jkstatus/
tomcat-connectors-1.2.48-src/jkstatus/build.xml
tomcat-connectors-1.2.48-src/jkstatus/conf/
tomcat-connectors-1.2.48-src/jkstatus/conf/jkstatus-tasks.xml
tomcat-connectors-1.2.48-src/jkstatus/src/
tomcat-connectors-1.2.48-src/jkstatus/src/share/... Skip ...
… Skip…
[apache@Test1 install]$ cd tomcat-connectors-1.2.48-src/native
[apache@Test1 native]$ ls
aclocal.m4 common configure libtool netscape TODO.txt
apache-2.0 config.log configure.ac Makefile README.txt
buildconf.sh config.nice docs Makefile.am scripts
BUILDING.txt config.status iis Makefile.in STATUS.txt
2) configure, make, make install 명령어로 컴파일한다.
$ ./configure --with-apxs=${APACHE_INSTALL_DIR}/bin/apxs
$ make $ make install
[apache@Test1 native]$ ./configure --with-apxs=/sw/apache/bin/apxs
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
...Skip...
[apache@Test1 apr-1.6.3]$ make
make[1]: Entering directory `/app/web/install/tomcat-connectors-1.2.48-
src/native/common'
/sw/apache/httpd-2.4.41/srclib/apr/apr-1.7.0/build/libtool --silent --mode=compile gcc -std=gnu99 -
I. -I/sw/apache/include -DHAVE_CONFIG_H -g -O2 -pthread -
DHAVE_APR -I/sw/apache/httpd-2.4.41/srclib/apr/apr-1.7.0/include/apr-1 -I/sw/apache/httpd-2.4.41/srclib/apr-util/apr-util-1.6.1/include/apr-1 -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -c
jk_ajp12_worker.c -o jk_ajp12_worker.lo
... Skip ...
make[1]: Leaving directory `/app/web/install/tomcat-connectors-1.2.48-
src/native/apache-2.0'
[apache@Test1 apr-1.6.3]$ make install
Making install in common
make[1]: Entering directory `/app/web/install/tomcat-connectors-1.2.48-
src/native/common'
make[1]: Nothing to be done for `install'.
make[1]: Leaving directory `/app/web/install/tomcat-connectors-1.2.48-
src/native/common'
Making install in apache-2.0
3) 생성된 mod_jk.so 파일 확인
$ ls {APACHE_INSTALL_DIR/modules/mod_jk.so
[apache@Test1 modules]$ pwd
/sw/apache/modules
[apache@Test1 modules]$ ls mod_jk.so
mod_jk.so
4) mod_jk 모듈과 톰캣을 연결하는 workers.properties 설정파일을 생성한다.
$ cd {APACHE_INSTALL_DIR}/conf
$ vi workers.properties
[apache@Test1 conf]$ pwd
/sw/apache/conf
[apache@Test1 conf]$ vi workers.properties
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=192.168.56.251
worker.worker1.type=ajp13
5) {APACHE_INSTALL_DIR}/conf/mod_jk.conf 파일에서 JKWorkersFile 에 이전에 설정해 놓은
mod_jk.conf 파일 내부의 workers.properties경로를 설정하여 workers.properties를 읽어온다.
$ cd {APACHE_INSTALL_DIR}/conf
$ vi mod_jk.conf
[apache@Test1 conf]$ pwd
/sw/apache/conf
[apache@Test1 conf]$ vi mod_jk.conf
<IfModule mod_jk.c>
JKWorkersFile "/sw/apache/conf/workers.properties"
</IfModule>
6) server.xml하단에 플러그인 옵션을 작성한다.
AJP 1.3 Connector의 주석을 해제하고 address 값을 수정한다.
$ cd ${TOMCAT_INSTALL_DIR}/conf
$ vi server.xml
…skip…
<Connector protocol="AJP/1.3"
address="192.168.56.251"
port="8009"
redirectPort="8443" secretRequired="false" />
…skip…
7) httpd.conf 하단에 해당 URI 확장자로 들어오는 Request는 workers.properties의 worker1 워커가 처리하도록 플러그인 옵션을 작성
$ vi {APACHE_INSTALL_DIR} httpd.conf
…skip…
Include conf/mod_jk.conf
LoadModule jk_module modules/mod_jk.so
<IfModule mod_jk.c>
JkWorkersFile conf/workers.properties
JkMount /*.do worker1
JkMount /*.jsp worker1
</IfModule>
8-1) 연동설정 확인을 위해 아파치를 재 기동 후 톰캣으로 어플리케이션을 호출
8-2) 연동설정 확인을 위해 아파치를 통해 session 카운트 jsp를 호출