August 25, 2005

Apache + Tomcat with mod_jk.so

安裝 Tomcat
wget http://archive.apache.org/dist/jakarta/tomcat-5/v5.5.11/bin/jakarta-tomcat-5.5.11.tar.gz
tar zxf jakarta-tomcat-5.5.11.tar.gz -C /usr/local
mv /usr/local/jakarta-tomcat-5.5.11 /usr/local/tomcat
下載 JDK 5.0 http://java.sun.com/j2se/1.5.0/download.jsp
chmod +x jdk-1_5_0_04-linux-i586.bin
./jdk-1_5_0_04-linux-i586.bin
mv jdk1.5.0_04 /usr/local/java
解開後放到 /usr/local/java
編輯一個 script for tomcat (/usr/local/bin/tomcat.sh)
#!/bin/sh
export JAVA_HOME=/usr/local/java
export CATALINA_HOME=/usr/local/tomcat
case $1 in
   start)
     /usr/local/tomcat/bin/startup.sh
     ;;
   stop)
     /usr/local/tomcat/bin/shutdown.sh
     ;;
esac
啟動 tomcat 用 tomcat.sh start, 關閉用 tomcat.sh stop
註: 在啟動 tomcat 前, JAVA_HOME, CATALINA_HOME 變數是必要的

編譯 mod_jk.so
wget http://archive.apache.org/dist/jakarta/tomcat-5/v5.5.11/src/jakarta-tomcat-5.5.11-src.tar.gz
tar zxf jakarta-tomcat-5.5.11-src.tar.gz
cd jakarta-tomcat-5.5.11-src/jakarta-tomcat-connectors/jk/native
./buildconf.sh
./configure --with-apxs=/usr/local/apache/bin/apxs
make
cp apache-1.3/mod_jk.so /usr/local/apache/libexec
註: 加 mod_jk.so 的用意就是可以用 JkMount 把 webapps 下的目錄 mount 到 DocumentRoot, 使可以不用打 :8080

設定 Apache
在 httpd.conf 加入
LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c
JkWorkersFile conf/mod_jk.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
# 指定那些檔案、目錄要用 Tomcat 去跑
JkMount /*.jsp ajp13
JKMount /jsp-examples/* ajp13
註: apache 在編譯時, configure 需加入 --enable-module=so 參數
在 apache conf 目錄下建編立 mod_jk.properties, 內容如下
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/java
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
註: ajp13 指 Apache JServ Protocol version 1.3

啟動 tomcat, 重新啟動 apache, 連連看
http://[your host]/index.jsp
http://[your host]/jsp-examples/
若有看到網頁, jsp 範例程式也正常, 大功告成!

Posted by pank at August 25, 2005 07:25 PM
Comments
Post a comment













Remember personal info?