使用jakarta-tomcat-connectors整合apache2和tomcat

1 Installing Apache2

下載apache
wget -c http://apache.mirror.phpchina.com/httpd/httpd-2.2.4.tar.bz2
解壓縮後進入目錄進行配置

./configure --enable-module=so --enable-module=usertrack --enable-modules=fastcgi --enable-info --enable-suexec --with-mpm=worker --enable-expires --enable-headers --enable-deflate --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache

make && make install

Edit /usr/local/apache2/conf/httpd.conf and change(修改apache2配置文件):

加入
DirectoryIndex index.htm index.html index.php index.xhtml index.shtml

/usr/local/apache2/bin/apachects start
啓動apache2

2 Installing JDK (Java Development Kit) or JRE(Java Runtime Environment)

http://java.sun.com
下載 jdk 或 jre

chmod +x jre-6u4-linux-i586.bin
Now execute the file:
./jre-6u4-linux-i586.bin
mv jre1.6.0_04 /usr/local/

Now we need to set the JAVA_HOME environment variable. Add the following at the end of /etc/profile just after export PATH.

vi /root/.bashrc
加入
JAVA_HOME=/usr/local/jre1.6.0_04
PATH=$JAVA_HOME:$JAVA_HOME/bin:$PATH
#CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH

重新登陸系統後
echo $JAVA_HOME
就會打印JAVA_HOME

3 Installing Tomcat
http://tomcat.apache.org
下載tomcat

執行
tar xvzf apache-tomcat-6.0.14.tar.gz

進入
TOMCAT_HOME/bin/

執行./startup.sh

啓動 進入 http://localhost:8080/ 就表示成功

4 Installing and configuring mod_jk
(1) cd /usr/src

(2) 首先下載(wget http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz)
http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz

(3) tar xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz

(4) cd jakarta-tomcat-connectors-1.2.15-src/jk/native

(5) Now you are ready to create the custom configure file for your system. Execute the following:

./buildconf.sh

如果提示失敗,最好下載
autoconf,automake,libtool


This will create a configure file in the
/usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native directory.

(6) Execute the following command in order to configure mod_jk for your system.
Important note: You will need to have apxs2 (APache eXtension tool) installed and configured with Apache.
If you do not have it, as was my case, you can download and install the apache2-threaded-dev package
(which replaced the former apache-dev package) from www.debian.org.
At the time of this writing, the Debian package archive at www.debian.org was down and
they referred me to their temporary site until they resolved their issues pdo.debian.net.
I found the apache2-threaded-dev package and was able to install it successfully.
Be sure to include the correct location apxs2 on your system in the path of the command.


./configure --with-apxs=/usr/local/apache2/bin/apxs

(7) 執行make

在執行make 時可能會出現

libtool: compile: unable to infer tagged configuration
libtool: compile: specify a tag with `--tag'
make[1]: *** [jk_ajp12_worker.lo] Error 1
make[1]: Leaving directory `/usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/common'
make: *** [all-recursive] Error 1

修改Makefile 和common/Makefile兩個文件

找到
LIBTOOL = /usr/share/apr-1.0/build/libtool --silent

改爲

LIBTOOL = /usr/share/apr-1.0/build/libtool --silent --tag CC



(8) make install 執行後應該在/usr/local/apache2/modules/可以看到mod_jk.so


5 Configuring Tomcat and Apache
Create the workers.properties file
Important note: Be sure to make a backup copy of your config files before modifying.
The workers.properties file contains the details about how each process is linked to Tomcat by defining workers that communicate through the ajpv13 protocol. Refer to the Workers HowTo for more detail.
1.First create the workers.properties file in your Apache2 root directory.
touch /usr/local/apache2/conf/workers.properties


2.Next, open the workers.properties file and add the following.
You can find many other examples of the workers.properties file on the internet,
but this is the one that I created and it seems to work fine with the other portions
that have already been configured in this tutorial.

在workers.properties加入以下內容:
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/jre1.6.0_01
ps=/
worker.list=worker1

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

3 保存並關閉文件

4. Now we need to open the /usr/local/apache2/conf/httpd.conf file and add the following lines at the bottom.
(httpd.conf is just for backward compatibility)

在最後加入 以下內容

LoadModule jk_module /usr/local/apache2/modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile /usr/local/apache2/conf/workers.properties

# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"


JkMount /*.jsp worker1
JkMount /*.do worker1

保存修改

(5) 修改
/usr/local/apache2/conf/extra/httpd-vhost.conf
修改,指定到應用程序中
DocumentRoot /var/www/test/
<Directory /var/www/test/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

並把 Options Indexes FollowSymLinks MultiViews
改成 Options FollowSymLinks MultiViews

保存修改

(6) 重啓 tomcat

然後 /usr/local/apache2/bin/apachectl restart
這樣apache就會把jsp請求交給tomcat來處理了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章