제목: 레드햇 9.0에서 Apache2, MySQL4, PHP4, Tomcat5 연동하기[7]
글쓴이: 예크디엠
글쓴날: 2004년 01월 07일 오후 05:52
URL : http://kltp.kldp.org/?story=04/01/07/5551551



--------------------------------------------------------------------------------
7. Tomcat Web Server Connector, JK2를 이용한 Apache2 웹서버와 Tomcat5의 연동

The Apache Jakarta Project 사이트에서 JK2 connector를 다운로드 받습니다. JK2의 binary 배포본은 Solaris와 WIN32용 만이 배포되고 있으므로 소스 형태의 배포본을 다운로드 받아야 합니다. http://jakarta.apache.org/site/sourceindex.cgi 에서 JK 2.0.2 Source Release tar.gz를 다운로드 받습니다.
배포파일 jakarta-tomcat-connectors-jk2-src-current.tar.gz

JK2 connector 소스를 컴파일 하면 얻을 수 있는 것이 mod_jk2.so 모듈입니다. Apache 웹서버와 Tomcat을 연동할 mod_jk2.so 모듈을 얻는 것이 컴파일의 목적입니다.

적당한 위치에서 압축을 풀어줍니다. 소스들을 컴파일하고 필요한 파일들을 이동시키면 더 이상 사용하지 않기 때문에 /usr/local/src에서 압축을 풀어주겠습니다.

shell> mv jakarta-tomcat-connectors-jk2-src-current.tar.gz /usr/local/src
shell> cd /usr/local/src
shell> tar xvfz jakarta-tomcat-connectors-jk2-src-current.tar.gz

압축이 풀리면 해당 디렉토리로 이동합니다. JK2 모듈을 얻기 위해서는 jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2로 이동합니다.

shell> cd /usr/local/src/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2

다음과 같이 configure를 실행하고 make로 컴파일을 합니다.

shell> ./configure --with-apxs2=/usr/sbin/apxs
shell> make

configure 옵션(autoconf 출력옵션) --with-apxs2[=FILE]
Apache 2.0 에서 공유할 DSO 모듈을 build하기 위해 사용합니다. FILE은 Apache apxs tool이 있는 경로를 나타냅니다.

make 시 에러가 발생할 수 있습니다. 이것은 autoconf 실행 중 설정되는 Apache 홈디렉토리가 RedHat에서는 /usr이므로, 컴파일 중에 필요로 하는 libtool 실행파일을 /usr/build/ 경로에서 찾는데 RedHat에서는 /var/www/build/ 경로에 존재하기 때문입니다. 따라서 문제가 발생할 경우에는 /var/www/build 디렉토리를 /usr 디렉토리 밑으로 복사하기 바랍니다.

문제없이 완료되었다면, 현재 디렉토리를 기준으로 ../build/jk2/apache2/의 경로에 mod_jk2.so 파일이 만들어졌을 것입니다. 이 파일을 아파치 모듈이 있는 디렉토리로 복사합니다.

shell> pwd
/usr/local/src/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2
shell> cd ../build/jk2/apache2
shell> ls
(mod_jk2.so 파일이 존재하는지 확인합니다.)
shell> cp mod_jk2.so /usr/lib/apache/
(레드햇에서는 아파치 모듈이 /usr/lib/apache 디렉토리에 위치합니다.)

/usr/local/src/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/conf/workers2.properties 파일을 /etc/httpd/conf/ 위치로 복사합니다.

shell> cd /usr/local/src/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/conf
shell> cp workers2.properties /etc/httpd/conf

이 파일은 Apache 웹서버에서 JK2 모듈을 사용할 때 필요한 여러가지 설정을 저장한 파일입니다. 이 파일 이외에 jk2.properties 파일이 중요한데, workers2.properties 파일이 Apache 쪽에서 JK2 모듈의 설정을 담당한다면, jk2.properties 파일은 Tomcat 쪽에서 JK2 모듈을 통한 웹서버와의 연결 설정을 담당합니다. Tomcat 5.0 버전에서는 JK2 connector를 처리할 수 있는 coyote connector가 기본설치 되어 있기 때문에 jk2.properties 파일을 Tomcat의 conf 디렉토리로 복사할 필요는 없습니다.

/etc/httpd/conf/httpd.conf 파일을 vi와 같은 편집기로 열어 LoadModule 부분을 찾아서 다음을 추가합니다.

LoadModule jk2_module lib/apache/mod_jk2.so

DirectoryIndex 부분을 찾아서 index.jsp를 추가합니다.

DirectoryIndex index.html index.html.var index.php index.phtml index.jsp

저장하고 편집기를 끝냅니다.
다음으로 /etc/httpd/conf 디렉토리에 복사해놓은 workers2.properties를 수정합니다. 아래의 설정 내용으로 구성합니다.

shell> cd /etc/httpd/conf
shell> vi worker2.properties

# Shared memory handling. Needs to be set.
[shm]
file=/var/log/httpd/shm.file
size=1048576

# Example socket channel, explicitly set port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1

# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009

# Announce a \"status\" worker
[status:status]

# Uri mapping
[uri:/jsp-examples/*]
worker=ajp13:localhost:8009

[uri:/servlets-examples/*]
worker=ajp13:localhost:8009

[uri:/tomcat-docs/*]
worker=ajp13:localhost:8009

[uri:/*]
worker=ajp13:localhost:8009

[uri:/status/*]
worker=status:status

(위 설정내용은 포스데이타㈜ BPM 사업추진반 장윤기 대리님이 작성한 <아파치와 톰캣 연동 및 로드 발란싱 구현>에서 발췌하여 수정한 것입니다.)
/usr/local/share/jakarta-tomcat-5.0.16/conf/jk2.properties를 수정합니다.

shell> cd /usr/local/share/jakarta-tomcat-5.0.16/conf
shell> vi jk2.properties

## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED
## WHEN YOU EDIT THE FILE.

## COMMENTS WILL BE _LOST_

## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.

# Set the desired handler list
# handler.list=apr,request,channelJni
#
# Override the default port for the socketChannel
channelSocket.port=8009
# Default:
# channelUnix.file=${jkHome}/work/jk2.socket
# Just to check if the the config is working
# shm.file=${jkHome}/work/jk2.shm
shm.file=/var/log/httpd/jk2.shm

# In order to enable jni use any channelJni directive
# channelJni.disabled = 0
# And one of the following directives:

# apr.jniModeSo=/opt/apache2/modules/mod_jk2.so

# If set to inprocess the mod_jk2 will Register natives itself
# This will enable the starting of the Tomcat from mod_jk2
apr.jniModeSo=inprocess

(위 설정내용은 포스데이타㈜ BPM 사업추진반 장윤기 대리님이 작성한 <아파치와 톰캣 연동 및 로드 발란싱 구현>에서 발췌하여 수정한 것입니다.)

모든 설정이 끝났습니다. 실행시키기 전에 /usr 디렉토리에서 /etc/httpd/conf 디렉토리에 연결된 링크 파일을 만들어줍니다. 이것은 mod_jk2.so 모듈을 컴파일 할 때 Apache Home Directory를 /usr 로 인식했기 때문에 workers2.properties 파일을 /usr/conf에서 찾기 때문입니다. 다음과 같이 실행합니다.

shell> cd /usr
shell> ln -s /etc/httpd/conf ./conf

모든 과정이 끝났으면 Tomcat과 Apache 웹서버를 실행시킵니다. ps 명령어로 현재 실행중인 process 목록을 확인해서 Tomcat과 Apache가 가동중인지 확인하고, 가동중이라면 실행을 중지시킵니다. 참고로 Tomcat의 Process CMD는 java입니다.

shell> ps -el
(프로세스가 존재하는지 확인)
shell> catalina.sh stop
(프로세스가 존재하면 실행중지)
shell> catalina.sh start

shell> /etc/init.d/httpd stop
(Apache 프로세스가 존재하면 실행중지)
shell> /etc/init.d/httpd start

또는 (Apache 프로세스가 존재할 경우)

shell> /etc/init.d/httpd restart

클라이언트에서 http://serverURL 로 연결해 봅니다. Apache Tomcat 웹페이지가 보이면 정상적으로 연동되어 작동하는 것입니다.

jk2.properties의 설정을 변경하였을 경우 이를 적용시키기 위해서는 Tomcat을 재가동 시켜주고 Apache 또한 다시 실행시켜주어야 합니다. workers2.properties의 설정을 변경한 경우에는 Apache 웹서버만 재가동시킵니다.

참고사항

- Apache Tomcat 연동에서 가장 중요한 부분은 자신의 시스템 또는 제공하려는 서비스에 알맞은 설정 파일을 작성하는 것입니다. 이 문서에서는 기본적인 설치만을 다루고 있기 때문에 자세한 사항은 Apache Jakarta 홈페이지를 방문해서 Tomcat 5.0 Document를 참고하기 바랍니다.

- 참고문서
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/index.html Tomcat 5.0 Document
http://www.javamania.pe.kr/index2.html [자바이야기>자료실] 아파치와 톰캣 연동 및 로드 발란싱 구현 (장윤기 님)
--------------------------------------------------------------------------------
답장(12)

KLTP - Korean Linux Tips Project
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2004/09/21 09:33 2004/09/21 09:33
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/293

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/293

« Previous : 1 : ... 5722 : 5723 : 5724 : 5725 : 5726 : 5727 : 5728 : 5729 : 5730 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Statistics Graph

Site Stats

Total hits:
186318
Today:
576
Yesterday:
745