본문 바로가기

리눅스

CentOS 6.4 YUM 기반 Apache + Tomcat6 연동하는 방법

반응형

CentOS 6.4 YUM 기반 Apache + Tomcat6 연동하는 방법

1. Apache 설치

yum install -y httpd httpd-devel

httpd-devel 설치 이유

  • apxs 포함 → mod_jk 컴파일 시 필요

2. Tomcat6 설치

yum install -y tomcat6 tomcat6-webapps tomcat6-admin-webapps

3. Tomcat 설정

(비권장) Invoker Servlet 설정

vim /usr/share/tomcat6/conf/web.xml
 
  <!-- This servlet has been deprecated due to security concerns. Servlets  -->
  <!-- should be explicitly mapped in web.xml                               -->
  <!--                                                                      -->
  <!-- The "invoker" servlet, which executes anonymous servlet classes      -->
  <!-- that have not been defined in a web.xml file.  Traditionally, this   -->
  <!-- servlet is mapped to the URL pattern "/servlet/*", but you can map   -->
  <!-- it to other patterns as well.  The extra path info portion of such a -->
  <!-- request must be the fully qualified class name of a Java class that  -->
  <!-- implements Servlet (or extends HttpServlet), or the servlet name     -->
  <!-- of an existing servlet definition.     This servlet supports the     -->
  <!-- following initialization parameters (default values are in square    -->
  <!-- brackets):                                                           -->
  <!--                                                                      -->
  <!--   debug               Debugging detail level for messages logged     -->
  <!--                       by this servlet.  [0]                          -->

    <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
 
           ...

    <!-- The mapping for the deprecated invoker servlet -->
    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

기존 설정 (주석 상태)

Invoker Servlet은 기본적으로 보안 문제로 비활성화되어 있음

주의
Invoker Servlet은 보안 취약점 때문에 운영환경에서는 사용 금지
반드시 필요한 경우에만 제한적으로 사용

Apache DocumentRoot를 Tomcat ROOT로 연결

cd /usr/share/tomcat6/webapps
ln -s /var/www/html ROOT
효과
Apache와 Tomcat이 동일한 정적 리소스 경로 사용

context.xml 설정

vim /usr/share/tomcat6/conf/context.xml
<!-- The contents of this file will be loaded for each web application -->
<!--<Context> -->
<Context reloadable="true" privileged="true">

옵션 설명

  • reloadable 클래스 변경 시 자동 리로드
  • privileged 관리자 권한 (필요 시만 사용)
728x90

4. mod_jk Connector 설치

소스 다운로드 및 컴파일

cd /usr/local/src
wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz

tar xvfz tomcat-connectors-1.2.37-src.tar.gz
cd tomcat-connectors-1.2.37-src/native

./configure --with-apxs=/usr/sbin/apxs
make && make install

모듈 설치 확인

ls -l /etc/httpd/modules/mod_jk.so

workers.properties 설정

vim /etc/httpd/conf.d/workers.properties
worker.list=ajp13

worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009

5. Apache 설정 (mod_jk 연동)

httpd.conf 설정

vim /etc/httpd/conf/httpd.conf
# mod_jk 로드
LoadModule jk_module modules/mod_jk.so

# workers 설정 파일
JkWorkersFile /etc/httpd/conf.d/workers.properties

# 로그 설정
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info

# 공유 메모리
JkShmFile /var/log/httpd/jk.shm

# URL 매핑
JkMount /*.jsp ajp13
JkMount /*.do ajp13
JkMount /servlet/* ajp13
JkMount /article/* ajp13
JkMount /uploadManager ajp13
JkMount /downManager ajp13
JkMount /alice-upload ajp13

6. Tomcat AJP Connector 확인

vim /usr/share/tomcat6/conf/server.xml
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
중요
mod_jk는 AJP 포트(8009) 사용
방화벽/SELinux 확인 필요

7. 서비스 실행

service tomcat6 start
service httpd start

chkconfig tomcat6 on
chkconfig httpd on

8. 동작 확인

브라우저 접속

http://서버IP/test.jsp
  • JSP 요청이 Tomcat으로 전달되면 정상

9. 트러블슈팅

mod_jk 로그 확인

tail -f /var/log/httpd/mod_jk.log

Tomcat 로그 확인

tail -f /var/log/tomcat6/catalina.out

포트 확인

netstat -ntlp | grep 8009

 

728x90
반응형