JSP CENT OS 5 세팅법

#########################################################
tomcat + apache + java + php + mysql + zendoptimizer 설치
#########################################################
http://jakarta.apache.org/site/downloads/
http://archive.apache.org/dist/tomcat/
#########################################################

mysql-4.0.27.tar.gz
httpd-2.0.53.tar.gz
php-4.4.2.tar.gz
jdk-1_5_0_04-linux-i586.bin
jakarta-tomcat-5.0.28.tar.gz
jakarta-tomcat-connectors-jk-1.2.6-src.zip
mysql-connector-java-5.0.6.tar.gz

######################################################
1. mysql 설치
######################################################

tar xvfpz mysql-4.0.27.tar.gz

groupadd mysql
useradd -g mysql -M mysql -s /sbin/nologin
-4.1미만
 ./configure \
 --prefix=/usr/local/mysql --localstatedir=/db \
 --enable-assembler \
 --with-thread-safe-client --with-mysqld-user="mysql" \
 --with-client-ldflags=-all-static \
 --with-mysqld-ldflags=-all-static \
 --with-readline --without-debug \
 --without-docs --without-bench \
 --with-charset=euc_kr \
 --without-innodb # innodb를 비활성화려면 추가.

-4.1이상
 ./configure \
 --prefix=/usr/local/mysql --localstatedir=/db \
 --enable-assembler \
 --with-thread-safe-client --with-mysqld-user="mysql" \
 --with-client-ldflags=-all-static \
 --with-mysqld-ldflags=-all-static \
 --with-readline --without-debug \
 --without-docs --without-bench \
 --with-charset=euckr

make && make install

환경설정을 다시해야할 경우 make distclean 실행

ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/
ln -s /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

vi /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"

vi /etc/profile
pathmunge /usr/local/mysql/bin

패스워드 지정
/usr/local/mysql/bin/mysqladmin -u root password "암호"

####################################################
apache 설치
####################################################

export CFLAGS="${CFLAGS} -DEAPI -DHARD_SERVER_LIMIT=1024 -DDEFAULT_SERVER_LIMIT=1024"

tar xvfpz httpd-2.0.53.tar.gz
./configure --prefix=/usr/local/apache --enable-rewrite=shared --enable-info=static --enable-so --enable-ssl --with-ssl=/usr --enable-mods-shared=ssl

make && make install

-----------------------------------------------------------------
#ServerName www.example.com:80 ==> #제거후 domain name으로 수정하거나 localhost로 수정
ex) ServerName localhost:80
AddDefaultCharset ISO-8859-1   ==> AddDefaultCharset utf8또는 euc_kr로 수정
ex)
AddDefaultCharset euc_kr
-----------------------------------------------------------------
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S85httpd
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd 
/etc/rc.d/init.d/httpd start


########################################################
php설치
########################################################

./configure \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-freetype-dir \
--with-png-dir \
--with-gdbm \
--with-db \
--with-gd \
--with-zlib \
--with-iconv \
--with-mbstring \
--enable-track-vars=yes \
--with-mod-charset \
--with-language=korean \
--with-charset=euc_kr \
--disable-debug \
--with-xml \
--enable-inline-optimization \
--enable-memory-limit # 사용자 개별 limit 적용하려면 추가.

make && make install

cp php.ini-dist /usr/local/lib/php.ini

vi /usr/local/apache2/conf/httpd.conf
-------------------------------------------------------
LoadModule php4_module lib/apache/libphp4.so 확인(php4)
LoadModule php5_module        modules/libphp5.so 확인(php5)

DirectoryIndex 에 다음사항을 추가
DirectoryIndex index.html index.htm index.shtml index.php index.php4 index.php3 index.phtml index.cgi index.jsp

PHP 확장 타입 추가
AddType application/x-httpd-php .php .php3 .htm .html .phtml .inc .ph .jsp
AddType application/x-httpd-php-source .phps

cgi 실행 주석제거, pl추가
AddHandler cgi-script .cgi .pl

<directory /home/> 정책추가
<Directory /home/>
   AllowOverride FileInfo AuthConfig Limit
   Options MultiViews  
   <Limit GET POST OPTIONS PROPFIND>
       Order allow,deny
       Allow from all
       Deny from env=go_out
   </Limit>
   <LimitExcept GET POST OPTIONS PROPFIND>
       Order deny,allow
       Deny from all
   </LimitExcept>
</Directory>

로그파일 설정(정책 : error_log만 설정)
ErrorLog /usr/local/apache/logs/error_log
-->
ErrorLog /log/httpd/error_log
로 경로변경
CustomLog /log/httpd/access_log common

디렉토리 뷰 삭제(index)
<Directory "/usr/local/apache/htdocs">
Options FollowSymLinks MultiViews
모든 디렉토리에 index를 지워준다.
------------------------------------------------------

php.ini 설정
------------------------------------------------------
vi /usr/local/lib/php.ini
register_globals = Off -> On
allow_url_fopen = Off
upload_max_filesize = 20M
------------------------------------------------------
/usr/local/apache2/bin/apachectl configtest
아파치 문법 테스트

[참고] 아파치 가동시 아래와 같은 에러가 발생할 경우

Syntax error on line 232 of /usr/local/apache/conf/httpd.conf:
Cannot load /usr/local/apache/modules/libphp5.so into server: cal/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission
 
오류에 대한 해결 방법
vi /etc/sysconfig/selinux
SELINUX=disable
하고 재부팅한다


######################################################
Zend Optimizer 설치
https://www.zend.com에서 Zend 최신버전을 다운
php 5.x대는 Zend 3.2이상에서만 지원된다.
######################################################
cd /usr/local/src
tar zxvf ZendOptimizer-2[1].1.0b-linux_glibc21-i386.tar.gz
cd ZendOptimizer-2.1.0b-linux_glibc21-i386
./install.sh
계속 Enter

########################################################
java설치
########################################################

jdk-1_5_0_04-linux-i586.bin을 다운 받는다.

chmod 755 jdk-1_5_0_04-linux-i586.bin
./jdk-1_5_0_04-linux-i586.bin
ln -s /usr/local/src/jdk1.5.0_04 /usr/local/java

vi /etc/profile
설정
---------------------------------
APACHE2_HOME=/usr/local/apache
JAVA_HOME=/usr/local/java
PATH=$PATH:$JAVA_HOME/bin:$APACHE2_HOME/bin
export PATH

를 맨위에 추가시켜 준다.
---------------------------------
source /etc/profile
변경된 설정을 시스템에 적용

java를 실행
옵션들이 보이면 설치가 성공한것임

##################################################
tomcat설치
##################################################

jakarta-tomcat-5.0.28.tar.gz

tar xvfpz jakarta-tomcat-5.0.28.tar.gz
ln -s /usr/local/src/jakarta-tomcat-5.0.28 /usr/local/tomcat
cd /usr/local/tomcat/bin
./catalina.sh start  or  ./startup.sh

http://localhost:8080또는 http://설치한주소:8080
정상적으로 tomcat이 작동되고 있다면 브라우저에 tomcat관련 문서가 나온다.

----------------------------
tomcat shutdown
./catalina.sh stop
./shutdown.sh
----------------------------
vi /etc/profile
----------------------------
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$APACHE2_HOME/bin
export PATH
----------------------------
----------------------------
APACHE2_HOME=/usr/local/apache
JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$APACHE2_HOME/bin
export JAVA_HOME
export CATALINA_HOME
export APACHE2_HOME
export PATH

JAVA_HOME이 정의되지 않았다고 나오고 실행이 안되면
위와 같이 전부 export해주면 해결됨
실행이 되면 상관없음
----------------------------
source /etc/profile
현재 tomcat이 운영중이라면 shutdown하고 다시 실행하자
catalina.sh stop
catalina.sh start
----------------------------

vi /etc/rc.d/init.d/tomcat 실행 스크립트
--------------------------------------------------------------------
#!/bin/sh

TOMCAT_PROG=tomcat

# if TOMCAT_USER is not set, use tomcat like Apache HTTP server
if [ -z "$TOMCAT_USER" ]; then
 TOMCAT_USER="root"
fi

RETVAL=0

# start and stop functions
start() {
 echo -n "Starting tomcat: "
 su -l $TOMCAT_USER -c '/usr/local/tomcat/bin/startup.sh'
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
 return $RETVAL
}

stop() {
 echo -n "Stopping tomcat: "
 su -l $TOMCAT_USER -c '/usr/local/tomcat/bin/shutdown.sh'
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat /var/run/tomcat.pid
 rm -rf /usr/local/jakarta-tomcat/work/*
}

# See how we were called.
case "$1" in
start)
 start
;;
stop)
 stop
;;
restart)
 stop
 # Ugly hack
 # We should really make sure tomcat is stopped before leaving stop
 sleep 2
 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit $RETVAL
--------------------------------------------------------------------
이렇게 스크립트를 만들어 놓으면 다음부터는
톰캣을 시작할때 명령어 하나면 쳐주면 된다.

시작
service tomcat start
중지
service tomcat stop

참고)데몬 실행순서
톰캣이 기동된후 아파치가 실행되어야 한다.


########################################################
mod_jk 설치하기

mod_jk2는 2004년부터 공식적으로 지원을 중단해서
최신버전 톰캣에서는 적용되지 않는다.
따라서 현재 최신 버전까지 모두 지원되고 있는
mod_jk를 이용해서 톰캣과 아파치를 연결한다.
mod_jk는 가능한 최신버전을 깔아준다.

최신버전 다운
http://tomcat.apache.org/download-connectors.cgi

########################################################

unzip jakarta-tomcat-connectors-jk-1.2.6-src.zip

./buildconf.sh
./configure --with-apxs2=/usr/local/apache/bin/apxs

make && make install

--------------------------------------------------------------------
mod_jk.so 가 /usr/local/apache2/modules 디렉토리 안에 있고, 권한은 755로 설정되어있는지 확인한다.
--------------------------------------------------------------------

☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
아파치를 톰캣에 연결하기
(최중요 부분)
★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆

--------------------------------------------------------------------
아파치와 톰캣을 연결해 주기 위해 설정해야 하는 파일은
세가지이다.

workers.properties
mod_jk.conf
httpd.conf
--------------------------------------------------------------------

1. workers.properties

/usr/local/apache2/conf 디렉토리에 workers.properties
라는 이름의 파일을 만들고 아래의 내용을 입력한 후 저장한다.

--------------------------------------------------------------------

workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/java
ps=/

worker.list=ajp13

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

--------------------------------------------------------------------
참고
cp /usr/local/src/tomcat-connectors-1.2.23-src/conf/workers.properties /usr/local/apache2/conf/
처럼 복사해서 설정만 바꿔줘도 된다.

2. mod_jk.conf

/usr/local/apache2/conf 디렉토리에 mod_jk.conf
라는 이름의 파일을 만들고 아래의 내용을 입력한 후 저장한다.

--------------------------------------------------------------------

JkWorkersFile /usr/local/apache/conf/workers.properties
JkLogFile /log/jk/mod_jk.log
JkLogLevel warn
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkRequestLogFormat "%w %V %T"
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlet ajp13
JkMount /WEB-INF/* ajp13
JkMount /WEB-INF ajp13
JkMount /jsp-examples/* ajp13
JkMount /jsp-examples ajp13

--------------------------------------------------------------------

3. httpd.conf
vi /usr/local/apache2/conf/httpd.conf
제일 밑에
include "/usr/local/apache2/conf/mod_jk.conf"
추가해주고, 아파치 재 시작.

http://Web_server_name_or_IP에 접속해서 성공하면 연결성공.
http://Web_server_name_or_IP/jsp-examples
http://Web_server_name_or_IP/servlets-examples
도 확인해 본다.

########################################################
가상도메인 설정하기
httpd.conf, virtualhost.conf server.xml
이 3파일이 필요하다.
########################################################

1.httpd.conf 편집

NameVirtualHost 222.239.223.109

vi /usr/local/apache2/conf/httpd.conf
제일 아래에
include "/usr/local/apache/conf/virtualhost.conf"
추가해 준다.

2.virtualhost.conf 편집

vi /usr/local/apache/conf/virtualhost.conf

<VirtualHost 222.239.223.109>
ServerAdmin webmaster@aaa.com
DocumentRoot /home/aaa.com
ServerName aaa.com
ServerAlias www.aaa.com
ErrorLog /log/httpd/aaa-error_log
CustomLog /log/httpd/aaa-access_log common
JkLogFile /log/jk/aaa-jk.log
JkLogLevel warn
JkMount /*.jsp ajp13
</VirtualHost>


※주의
/log/httpd/
/log/jk
폴더는 만들어 주어야 한다.

3. server.xml 편집

cd /usr/local/tomcat/conf


vi server.xml

제일 아래로 이동
--------------------------------------------------------------------
 <Host name="aaa.com" debug="0" appBase="/home/aaa.com/public_html">
 <Alias>www.aaa.com</Alias>
 </Host>
--------------------------------------------------------------------

cd /usr/local/tomcat/conf/Catalina
추가할 도메인 이름으로 폴더를 하나를 만든다.


mkdir aaa.com
cd aaa.com
vi ROOT.xml
-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
 <Context docBase="/home/aaa.com" privileged="true" reloadable="true">
 </Context>
------------------------------------
docBase에 서비스 받고자 할 디렉토리를 써준다.

<?xml version='1.0' encoding='utf-8'?>
<Context workDir="work/Catalina/jy.com/_" path="/" displayName="ShoppingShop" docBase="" useNaming="false" reloadable="true">
  <Resource type="javax.sql.DataSource" description="Oracle DB Connection" auth="Container" name="jdbc/myoracle"/>
</Context>


#######################################################
 Mysql-Connector-Java(JDBC셋업)
#######################################################

tar xvfpz mysql-connector-java-5.0.6.tar.gz
chown -R root.root mysql-connector-java-5.0.6


1) java에 class file 등록하기
cp mysql-connector-java-5.0.6-bin.jar /usr/local/java/jre/lib/ext/.
(물론 /usr/local/java는 $JAVA_HOME로 등록이 되어 있어야 한다.)

2) tomcat에 class file 등록
cp mysql-connector-java-5.0.6-bin.jar /usr/local/tomcat/common/lib/.
(물론 /usr/local/tomcat은 $CATALINA_HOME에 등록되어 있어야 한다.)

------------------------------------
vi /etc/profile

아랫부분을 추가한다

CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/ext/mysql-connector-java-3.1.13-bin.jar:/usr/local/tomcat/common/lib:servlet-api.jar
export CLASSPATH
------------------------------------
source /etc/profile


cd $JAVA_HOME/bin 으로 가서,

./javap com.mysql.jdbc.Driver 실행후
------------------------------------------------------------------------
Compiled from "Driver.java"

public class com.mysql.jdbc.Driver extends com.mysql.jdbc.NonRegisteringDriver implements java.sql.Driver{

    public com.mysql.jdbc.Driver()       throws java.sql.SQLException;

    static {};

}
------------------------------------------------------------------------
라는 메시지가 뜨면 정상


------------------------------------------------
jdbc드라이버를 이용한 java와 mysql의 연동 테스트
------------------------------------------------

아래 내용을 저장
vi jdbc.java
------------------------------------------------------------------------
import java.sql.*;
      class jdbc {
        public static void main(String argv[]) {
             try {
                Class.forName("org.gjt.mm.mysql.Driver");
                System.out.println("jdbc driver load success");
             } catch (ClassNotFoundException e) {
                System.out.println(e.getMessage());
             }
             try {
                String url = "jdbc:mysql://127.0.0.1:3306/mysql";
        Connection con = DriverManager.getConnection(url,"root","패스워드");
                System.out.println("mysql sucess");
                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery("select user from user where user='root'");
                System.out.println("Got result:");
                while(rs.next()) {
                     String no= rs.getString(1);
                     String tblname  = rs.getString(1);
                     System.out.println(" no = " + no);
                     System.out.println(" tblname= "+ tblname);
                }
             stmt.close();
             con.close();
             } catch(java.lang.Exception ex) {
                ex.printStackTrace();
             }
        }
      }
------------------------------------------------------------------------
저장하고 나온다.

javac jdbc.java 컴파일해주고
java jdbc 실행시켜주면

아래 메세지가 나오면 성공
jdbc driver load success
mysql sucess
Got result:
 no = root
 tblname= root
 no = root
 tblname= root


---------------
jsp 연동 테스트
---------------

/usr/local/tomcat/webapps/ROOT 으로 가서,

vi mysql.jsp
------------------------------------------------
<%@ page import="java.sql.*"
contentType="text/html;charset=euc-kr"%>
<%
String DB_URL = "jdbc:mysql://localhost:3306/mysql";
String DB_USER = "root";
String DB_PASSWORD= "패스워드";
Connection conn;
Statement stmt;
try {
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USER,
DB_PASSWORD);
stmt = conn.createStatement();
conn.close();
out.println("MySQL 연결 성공");
} catch(Exception e)
{out.println(e);}
%>
------------------------------------------------
Mysql 연결 성공
이라는 글자가 나오면 성공


마지막으로

vi /usr/local/tomcat/conf/server.xml
이부분으로 찾아서
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector port="8080" maxHttpHeaderSize="8192"


Connector port="8080" ---> Connector port=""
로 해주어서 8080포트로의 접속을 막아준다.

--------------------------------------------------
/etc/profile 최종
--------------------------------------------------
APACHE2_HOME=/usr/local/apache
JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$APACHE2_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/ext/mysql-connector-java-5.1.7-bin.jar:/usr/local/tomcat/common/lib:$CATALINA_HOME/common/lib/servlet-api.jar
export JAVA_HOME=/usr/local/java
export CATALINA_HOME="/usr/local/tomcat"
export APACHE2_HOME
export PATH
export CLASSPATH
export LANG="ko_KR.euc-KR"

2010/04/14 09:36 2010/04/14 09:36

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다