Tomcat JSP Server
-------------------------------------------------------------------
참고 사이트 : http://tomcat.apache.org/
-------------------------------------------------------------------
1. JAVA 컴파일 프로그램 설치
- 참고
기본적으로 아파치 서버가 설치되어 있어야 한다.
-------------------------------------------------------------------
JDK 다운 : http://java.sun.com/javase/downloads/index.jsp
jdk-6u11-linux-i586-rpm.bin (다운로드)
-------------------------------------------------------------------
1-1. JAVA 컴파일 프로그램 다운 & 압축해제 & 설치
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd Desktop
[root@localhost Desktop]# ls
jdk-6u11-linux-i586-rpm.bin
[root@localhost Desktop]# sh jdk-6u11-linux-i586-rpm.bin
- 소스를 make & make install 까지 해 놓은 파일이 bin(바이너리파일)이고 이를 rpm으로 만든것이 rpm.bin파일 이다.
- 중략
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
Done.
[root@localhost Desktop]# ls
jdk-6u11-linux-i586.rpm
sun-javadb-client-10.4.1-3.1.i386.rpm
sun-javadb-common-10.4.1-3.1.i386.rpm
sun-javadb-core-10.4.1-3.1.i386.rpm
sun-javadb-demo-10.4.1-3.1.i386.rpm
sun-javadb-docs-10.4.1-3.1.i386.rpm
sun-javadb-javadoc-10.4.1-3.1.i386.rpm
jdk-6u11-linux-i586-rpm.bin
[root@localhost Desktop]#
-------------------------------------------------------------------
1-2. JAVA 컴파일 프로그램 설치
[root@localhost Desktop]# rpm -Uvh jdk-6u11-linux-i586.rpm
준비 중... ########################################### [100%]
jdk-1.6.0_11-fcs 패키지는 이미 설치되어 있습니다 - 내컴퓨터에는 이미 설치가 되어 있었다.
[root@localhost Desktop]# rpm -qa | grep jdk
jdk-1.6.0_11-fcs
ldapjdk-4.18-2jpp.3.el5
[root@localhost Desktop]#
[root@localhost Desktop]# javac - 자바 컴파일러 프로그램의 옵션이 제대로 나와야설치 되어 있는지 확인한다.
Eclipse Java Compiler v_677_R32x, 3.2.1 release
Copyright IBM Corp 2000, 2006. All rights reserved.
- 중략
-? -help print this help message
-v -version print compiler version
-showversion print compiler version and continue
[root@localhost Desktop]#
[root@localhost Desktop]# cd /usr/java/jdk1.6.0_11/ - 설치된 경로로 이동한다.
-------------------------------------------------------------------
1-3. /etc/profile 파일에 경로를 재 지정
[root@localhost jdk1.6.0_11]# vi /etc/profile
6 #java_enviroment
7 JAVA_HOME=/usr/java/jdk1.6.0_11
8 PATH=$JAVA_HOME/bin:$PATH
9 export JAVA_HOME
[root@localhost jdk1.6.0_11]# source /etc/profile - 프로파일에 적용시킨다. 설정후에는 항상 적용시킨다.
[root@localhost jdk1.6.0_11]# echo $PATH
/usr/java/jdk1.6.0_11/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@localhost jdk1.6.0_11]# java - 제대로 적용이 되었는지 확인한다.
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
- 중략
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
[root@localhost jdk1.6.0_11]#
-------------------------------------------------------------------
2. Tomcat 설치
-------------------------------------------------------------------
Tomcat 홈페이지 : http://jakarta.apache.org/
apache-tomcat-5.5.12.tar.gz (다운로드)
-------------------------------------------------------------------
2-1. Tomcat 다운 및 압축해제 & 설치
- Tomcat 서버는 압축 해제 = 설치 이다.
[root@localhost Desktop]# pwd
/root/Desktop
[root@localhost Desktop]# tar xvfz apache-tomcat-5.5.12.tar.gz
[root@localhost Desktop]# ls
apache-tomcat-5.5.12 apache-tomcat-5.5.12.tar.gz
[root@localhost Desktop]# mv apache-tomcat-5.5.12 /usr/local
[root@localhost Desktop]# cd /usr/local
[root@localhost local]# ls
apache bin games lib man sbin src
apache-tomcat-5.5.12 etc include libexec mysql share
[root@localhost local]#
-------------------------------------------------------------------
2-2. /etc/profile 파일에 경로를 재 지정
[root@localhost local]# vi /etc/profile
6 #java_enviroment
7 JAVA_HOME=/usr/java/jdk1.6.0_11
8 CATALINA_HOME=/usr/local/apache-tomcat-5.5.12
9 PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
10 export JAVA_HOME CATALINA_HOME
- 참고 : 아파치 명령어를 모든 곳에서 사용하도록 경로 지정
6 #java_enviroment
7 JAVA_HOME=/usr/java/jdk1.6.0_11
8 CATALINA_HOME=/usr/local/apache-tomcat-5.5.12
9 APACHE_HOME=/usr/local/apache
10 PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$APACHE_HOME/bin:$PATH
11 export JAVA_HOME CATALINA_HOME APACHE_HOME
[root@localhost local]# source /etc/profile
[root@localhost local]# echo $PATH
/usr/java/jdk1.6.0_11/bin:/usr/local/apache-tomcat-5.5.12/bin:/usr/java/jdk1.6.0_11/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@localhost local]#
[root@localhost local]# cd /usr/local/apache-tomcat-5.5.12/bin - tomcat의 명령어가 들어있는 폴더
[root@localhost bin]# pwd
/usr/local/apache-tomcat-5.5.12/bin
[root@localhost bin]# ls
bootstrap.jar digest.bat shutdown.bat tomcat5w.exe
catalina-tasks.xml digest.sh shutdown.sh tool-wrapper.bat
catalina.bat jmxaccessor-tasks.xml startup.bat tool-wrapper.sh
catalina.sh jsvc.tar.gz startup.sh version.bat
commons-daemon.jar service.bat tomcat-juli.jar version.sh
commons-logging-api.jar setclasspath.bat tomcat-native.tar.gz
cpappend.bat setclasspath.sh tomcat5.exe
[root@localhost bin]#
[root@localhost bin]# /usr/local/apache-tomcat-5.5.12/bin/startup.sh start - tomcat 시작
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost bin]# startup.sh stop - 경로가 제대로 지정되어 있는지 확인해 본다. or shutdown.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11네
[root@localhost bin]# startup.sh start
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost bin]# ps aux | grep java
root 8693 4.6 3.1 228616 32136 pts/2 Sl 10:10 0:02 /usr/java/jdk1.6.0_11/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/local/apache-tomcat-5.5.12/conf/logging.properties -Djava.endorsed.dirs=/usr/local/apache-tomcat-5.5.12/common/endorsed -classpath :/usr/local/apache-tomcat-5.5.12/bin/bootstrap.jar:/usr/local/apache-tomcat-5.5.12/bin/commons-logging-api.jar -Dcatalina.base=/usr/local/apache-tomcat-5.5.12 -Dcatalina.home=/usr/local/apache-tomcat-5.5.12 -Djava.io.tmpdir=/usr/local/apache-tomcat-5.5.12/temp org.apache.catalina.startup.Bootstrap start start
root 8780 0.0 0.0 5184 748 pts/2 S+ 10:11 0:00 grep java
[root@localhost bin]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 :::8080 :::* LISTEN - tomcat 서버의 서비스 포트는 8080 이다.
[root@localhost bin]#
-------------------------------------------------------------------
2-3. 웹브라우저에서 확인
http://www.bban2.co.kr:8080/
-------------------------------------------------------------------
3. Tomcat JSP 서버의 DocumentROOT 확인
[root@localhost ROOT]# pwd
/usr/local/apache-tomcat-5.5.12/webapps/ROOT
[root@localhost ROOT]# ls
RELEASE-NOTES.txt admin index.jsp tomcat-power.gif
WEB-INF favicon.ico jakarta-banner.gif tomcat.gif
[root@localhost ROOT]#
-------------------------------------------------------------------
4. 아파치 서버와 톰캣 서버의 연동
- 아파치 서버와 톰캣 서버를 연동시키기 위한 파일 - tomcat-connectors
-------------------------------------------------------------------
http://tomcat.apache.org/download-connectors.cgi
tomcat-connectors-1.2.27-src.tar.gz (다운로드)
-------------------------------------------------------------------
4-1. Tomcat-connectors 다운 & 압축 해제
[root@localhost Desktop]# pwd
/root/Desktop
[root@localhost Desktop]# tar xvfz tomcat-connectors-1.2.27-src.tar.gz
[root@localhost Desktop]# ls
tomcat-connectors-1.2.27-src tomcat-connectors-1.2.27-src.tar.gz
[root@localhost Desktop]# cd tomcat-connectors-1.2.27-src
[root@localhost tomcat-connectors-1.2.27-src]# ls
BUILD.txt LICENSE conf jkstatus support xdocs KEYS NOTICE docs native tools
-------------------------------------------------------------------
4-2. Tomcat-connectors 설치
[root@localhost tomcat-connectors-1.2.27-src]# vi BUILD.txt - Tomcat-connectors 설치 방법이 설명되어 있다.
24 For the impatient Apache admins:
25 $> cd native
26 $> ./configure --with-apxs=/usr/sbin/apxs (or where ever the apxs/apxs2 is)
27 $> make
28 $> su -c 'make install'
-------------------------------------------------------------------
4-2-1. 소스 설치한 아파치의 apxs파일 경로 확인
[root@localhost ~]# cd /usr/local/apache/bin/
[root@localhost bin]# ls
ab apu-1-config dbmmanage htcacheclean htpasswd logresolve
apachectl apxs envvars htdbm httpd rotatelogs
apr-1-config checkgid envvars-std htdigest httxt2dbm
-------------------------------------------------------------------
[root@localhost tomcat-connectors-1.2.27-src]# cd native/
[root@localhost native]# pwd
/root/Desktop/tomcat-connectors-1.2.27-src/native
[root@localhost native]# ls
BUILDING.txt Makefile.in STATUS.txt apache-1.3 common docs netscape
CHANGES NEWS TODO.txt apache-2.0 configure iis nt_service
Makefile.am README.txt aclocal.m4 buildconf.sh configure.in jni scripts
[root@localhost native]# ./configure --with-apxs=/usr/local/apache/bin/apxs --enable-EAPI - 아파치 서버에 모듈형태로 들어가게 된다.
-중략
...Enabling EAPI Support...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating apache-1.3/Makefile
config.status: creating apache-1.3/Makefile.apxs
config.status: creating apache-2.0/Makefile
config.status: creating apache-2.0/Makefile.apxs
config.status: creating common/Makefile
config.status: creating common/list.mk
config.status: creating common/jk_types.h
config.status: creating jni/Makefile
config.status: creating common/portable.h
config.status: executing depfiles commands
[root@localhost native]# make
- 중략
Making all in common
make[1]: Entering directory `/root/Desktop/tomcat-connectors-1.2.27-src/native/common'
make[1]: `all'를 위해 할 일이 없습니다
make[1]: Leaving directory `/root/Desktop/tomcat-connectors-1.2.27-src/native/common'
Making all in apache-2.0
make[1]: Entering directory `/root/Desktop/tomcat-connectors-1.2.27-src/native/apache-2.0'
make[1]: `all'를 위해 할 일이 없습니다
make[1]: Leaving directory `/root/Desktop/tomcat-connectors-1.2.27-src/native/apache-2.0'
[root@localhost native]# make install
- 중략
chmod 755 /usr/local/apache/modules/mod_jk.so
Please be sure to arrange /usr/local/apache/conf/httpd.conf...
make[1]: Leaving directory `/root/Desktop/tomcat-connectors-1.2.27-src/native/apache-2.0'
make[1]: Entering directory `/root/Desktop/tomcat-connectors-1.2.27-src/native'
make[2]: Entering directory `/root/Desktop/tomcat-connectors-1.2.27-src/native'
make[2]: `install-exec-am'를 위해 할 일이 없습니다
make[2]: `install-data-am'를 위해 할 일이 없습니다
make[2]: Leaving directory `/root/Desktop/tomcat-connectors-1.2.27-src/native'
make[1]: Leaving directory `/root/Desktop/tomcat-connectors-1.2.27-src/native'
[root@localhost native]#
[root@localhost native]# ls
BUILDING.txt Makefile.in TODO.txt buildconf.sh config.status iis nt_service
CHANGES NEWS aclocal.m4 common configure jni scripts
Makefile README.txt apache-1.3 config.log configure.in libtool
Makefile.am STATUS.txt apache-2.0 config.nice docs netscape
[root@localhost native]# cd apache-2.0/ - 현재 apache 2.X대를 사용하므로 이 폴더로 들어간다.
[root@localhost apache-2.0]# ls
Makefile Makefile.in bldjk.qclsrc mod_jk.a mod_jk.la mod_jk.so
Makefile.apxs Makefile.vc bldjk54.qclsrc mod_jk.c mod_jk.lo
Makefile.apxs.in NWGNUmakefile config.m4 mod_jk.dsp mod_jk.o
[root@localhost apache-2.0]# cd /usr/local/apache/modules/ - apache 서버의 모듈에 추가 되었는지 확인한다.
[root@localhost modules]# ls -l mod_jk.so
-rwxr-xr-x 1 root root 779290 12월 17 10:50 mod_jk.so
[root@localhost modules]#
-------------------------------------------------------------------
4-3. 환경설정파일 설정
[root@localhost modules]# cd /root/Desktop/tomcat-connectors-1.2.27-src
[root@localhost tomcat-connectors-1.2.27-src]# ls
BUILD.txt KEYS LICENSE NOTICE conf docs jkstatus native support tools xdocs
[root@localhost tomcat-connectors-1.2.27-src]# cd conf
[root@localhost conf]# ls
uriworkermap.properties workers.properties workers.properties.minimal
[root@localhost conf]# cp workers.properties /usr/local/apache/conf/ - Tomcat 서버의 설정파일을 복사한다.
[root@localhost conf]# cd /usr/local/apache/conf
[root@localhost conf]# ls
extra httpd.conf httpd.conf.bak magic mime.types original php.ini workers.properties
[root@localhost conf]# vi workers.properties
[root@localhost conf]# cat workers.properties
worker.list=bban2-worker
worker.bban2-worker.port=8009
worker.bban2-worker.host=localhost
worker.bban2-worker.type=ajp13
- 나머지 부분은 삭제해도 무방하다. 여기서 bban2은 호스트 네임이다.
[root@localhost ~]# hostname , # vi /etc/hosts, # vi /etc/sysconfig/network으로 확인
-------------------------------------------------------------------
[root@localhost bin]# vi /usr/local/apache/conf/httpd.conf
99 LoadModule jk_module modules/mod_jk.so - tomcat 모듈 추가, workers.properties의 설정을 보고 작동하게 된다.
161 <Directory />
162 Options FollowSymLinks
163 AllowOverride None
164 Order deny,allow
165 # Deny from all - allow from all로 수정해 준다. 수정해 주지 않으면 접근 권한이 없기 때문에 (도메인과 관련해서) 퍼미션 에러가 발생된다.
166 allow from all
167 </Directory>
215 <IfModule dir_module>
216 DirectoryIndex index.html index.html.var index.jsp
217 </IfModule>
445 # Virtual hosts
446 #Include conf/extra/httpd-vhosts.conf - virtual host의 설정이 되어 있다면 주석처리 해준다.
457 # Tomcat setting
458 Include conf/extra/tomcat.conf - Tomcat 모듈에 대한 설정파일이다.
[root@localhost conf]# cd extra
[root@localhost extra]# ls
httpd-autoindex.conf httpd-languages.conf httpd-ssl.conf
httpd-dav.conf httpd-manual.conf httpd-userdir.conf
httpd-default.conf httpd-mpm.conf httpd-vhosts.conf
httpd-info.conf httpd-multilang-errordoc.conf
[root@localhost extra]# vi tomcat.conf - Tomcat 모듈에 대한 설정파일을 생성한다.
[root@localhost extra]# cat tomcat.conf
#mod_jk setup
<IfModule mod_jk.c>
JkWorkersFile "/usr/local/apache/conf/workers.properties"
JkLogFile "/usr/local/apache/logs/mod_jk.log"
JkLogLevel emerg
JkMount /*.jsp bban2-worker
JkMount /servlet/* bban2-worker
</IfModule>
Alias /jsp-examples "/usr/local/apache-tomcat-5.5.12/webapps/jsp-examples"
<Directory "/usr/local/apache-tomcat-5.5.12/webapps/jsp-examples">
Options indexes FollowSymLinks
DirectoryIndex index.html index.htm index.jsp
</Directory>
[root@localhost extra]#
-------------------------------------------------------------------
4-4. 서비스 실행
- Tomcat 서버와 Apache 서버의 실행 순서
서비스 실행 : Apache start -> Tomcat start
서비스 종료 : Tomcat stop -> Apache stop
[root@localhost extra]# source /etc/profile
[root@localhost extra]# startup.sh stop
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost extra]# /usr/local/apache/bin/apachectl stop
[root@localhost extra]# /usr/local/apache/bin/apachectl start
[root@localhost extra]# startup.sh start
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost extra]#
-------------------------------------------------------------------
2-3. 웹브라우저에서 확인
http://www.bban2.co.kr/jsp-examples/
그리고 execute를 제대로 실행시켜야 한다.
바로 실행했을 경우에는 브라우저의 캐시 설정때문에 소스가 나올 경우가 있으니 새로고침(F5)을 해본다.
-------------------------------------------------------------------
[root@localhost bin]# vi /usr/local/apache/conf/httpd.conf
99 LoadModule jk_module modules/mod_jk.so - tomcat 모듈 추가, workers.properties의 설정을 보고 작동하게 된다.
161 <Directory />
162 Options FollowSymLinks
163 AllowOverride None
164 Order deny,allow
165 # Deny from all - allow from all로 수정해 준다. 수정해 주지 않으면 접근 권한이 없기 때문에 (도메인과 관련해서) 퍼미션 에러가 발생된다.
166 allow from all
167 </Directory>
215 <IfModule dir_module>
216 DirectoryIndex index.html index.html.var index.jsp
217 </IfModule>
445 # Virtual hosts
446 #Include conf/extra/httpd-vhosts.conf - virtual host의 설정이 되어 있다면 주석처리 해준다.
457 # Tomcat setting
458 Include conf/extra/tomcat.conf - Tomcat 모듈에 대한 설정파일이다.
[root@localhost conf]# cd extra
[root@localhost extra]# ls
httpd-autoindex.conf httpd-languages.conf httpd-ssl.conf
httpd-dav.conf httpd-manual.conf httpd-userdir.conf
httpd-default.conf httpd-mpm.conf httpd-vhosts.conf
httpd-info.conf httpd-multilang-errordoc.conf
[root@localhost extra]# vi tomcat.conf - Tomcat 모듈에 대한 설정파일을 생성한다.
[root@localhost extra]# cat tomcat.conf
#mod_jk setup
<IfModule mod_jk.c>
JkWorkersFile "/usr/local/apache/conf/workers.properties"
JkLogFile "/usr/local/apache/logs/mod_jk.log"
JkLogLevel emerg
JkMount /*.jsp bban2-worker
JkMount /servlet/* bban2-worker
</IfModule>
Alias /jsp-examples "/usr/local/apache-tomcat-5.5.12/webapps/jsp-examples"
<Directory "/usr/local/apache-tomcat-5.5.12/webapps/jsp-examples">
Options indexes FollowSymLinks
DirectoryIndex index.html index.htm index.jsp
</Directory>
[root@localhost extra]#
-------------------------------------------------------------------
4-4. 서비스 실행
- Tomcat 서버와 Apache 서버의 실행 순서
서비스 실행 : Apache start -> Tomcat start
서비스 종료 : Tomcat stop -> Apache stop
[root@localhost extra]# source /etc/profile
[root@localhost extra]# startup.sh stop
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost extra]# /usr/local/apache/bin/apachectl stop
[root@localhost extra]# /usr/local/apache/bin/apachectl start
[root@localhost extra]# startup.sh start
Using CATALINA_BASE: /usr/local/apache-tomcat-5.5.12
Using CATALINA_HOME: /usr/local/apache-tomcat-5.5.12
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-5.5.12/temp
Using JRE_HOME: /usr/java/jdk1.6.0_11
[root@localhost extra]#
-------------------------------------------------------------------
2-3. 웹브라우저에서 확인
http://www.bban2.co.kr/jsp-examples/
그리고 execute를 제대로 실행시켜야 한다.
바로 실행했을 경우에는 브라우저의 캐시 설정때문에 소스가 나올 경우가 있으니 새로고침(F5)을 해본다.
'Linux Server 구축 > 1-2. Web Server' 카테고리의 다른 글
Tomcat 6.0 & Apache Server 연동 중 Servlets 연동 문제 (0) | 2009.01.15 |
---|---|
ZendOptimizer (0) | 2008.12.17 |
PHPMyAdmin (0) | 2008.12.17 |
APM - PHP 소스설치 (0) | 2008.12.16 |
APM - Apache 소스설치 (0) | 2008.12.16 |
APM - MySQL 소스설치 (0) | 2008.12.16 |