2009. 2. 6. 18:37

Tomcat JSP server 설치


■ 준비 사항

1. JDK 설치

1.1 다운로드
--------------------------
http://java.sun.com 
--------------------------
에서 java se 버전 다운로드

# ls
jdk-6u12-linux-i586.bin

1.2. JDK 설치 파일 실행

# sh jdk-6u12-linux-i586.bin
..
more
...
[yes] 입력
..
Done.
# mv jdk-6u12-linux-i586.bin /usr/local
# cd /usr/local
# ls
# ln -s /usr/local/jdk1.6.0_12/ java  
<링크생성>

1.3. /etc/profile 에 환경변수 등록

# vi /etc/profile     < 환경 변수 등록>
..
# SET JAVA ENV
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar

..

# source /etc/profile       < 현재 쉘에 바로 적용 >
# javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
..              < 정상 등록되었음 >

# env
/usr/local/java/bin

JAVA_HOME=/usr/local/java

CLASSPATH=./usr/local/java/jre/lib/ext:/usr/local/java/lib/tools.jar



2. Tomcat  설치

2.1. Tomcat 다운로드 및 설치

---------------------------------
http://tomcat.apache.org
---------------------------------
< 현재 6.x 버전 까지 나와있으나 안정화 버전인 5.x 버전을 다운로드 >
< tomcat 서버는 압축 해제가 바로 서버 설치와 같다.>

# pwd
/usr/local
# wget
http://mirror.khlug.org/apache/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.tar.gz
# ls
apache-tomcat-5.5.27.tar.gz 

# tar -xvzf apache-tom*
# cd apache-to*
# ls
LICENSE  RELEASE-NOTES  bin     conf  server  temp     work
NOTICE   RUNNING.txt    common  logs  shared  webapps
# ln -s /usr/local/apache-tomcat-5.5.27 /usr/local/tomcat


2.2   /etc/profile 에 환경변수 등록

# SET JAVA ENV
export JAVA_HOME=/usr/local/java
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export CLASSPATH=.$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME
/common/lib/jsp-api.jar:$CATALINA_HOME/common/lib/servlet-api.jar


# source /etc/profile

# env
:/usr/local/tomcat/bin
:/usr/local/tomcat/common/lib/jsp-api.jar:/usr/local/tomcat/common/lib/servlet-api.jar



2.3. Tomcat 서버 시작

# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/local/java

# ps -ef | grep tomcat
root     24200     1  2 06:54 pts/2    00:00:02 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/common/endorsed -classpath :/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-logging-api.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root     24255  3559  0 06:55 pts/2    00:00:00 grep tomcat

# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/local/java

# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/local/java


2.4. 웹브라우저 확인



2.5. Tomcat manager 접속
2.5.1 환경설정

# vi /usr/local/tomcat/conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
 
<role rolename="admin"/>
  <role rolename="manager"/>
  <user username="admin" password="passwd" roles="admin,manager"/>

  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

2.5.2. 톰캣서버 재시작 (스톱 -> 시작) 스크립트 실행>

# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/local/java
# /usr/local/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/local/java
#

2.5.3 웹브라우저 확인
첫페이지의 Tomcat manager << 항목에서 확인할 수 있다.
tomcat 서버의 전반적인 상황을 파악할 수 있다. <server status>


2.6. JSP 간단 테스트


# pwd
/usr/local/apache-tomcat-5.5.27/webapps
# mkdir  home
# cd home/
# pwd
/usr/local/apache-tomcat-5.5.27/webapps/home
# cp -R ../ROOT/WEB-INF ./
# vi  time.jsp

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.Date" %>
<%
        Date nowTime = new Date();
%>

<html>
<head>
<title>JSP time test</title>
</head>

<body>
NOw Time is <%= nowTime %>
</body>

</html>

2.6.1. tomcat server 재시작
2.6.2. 웹브라우저 확인

http://IP:8080/home/time.jsp