Garey's Blog–FreeBSD/PHP/GoLang

十二月 22nd, 2009

Linux下Tomcat整合Apache安装笔记

4,406 views, Linux, by garey.

1,下载所需安装文件
httpd-2.2.14.tar.gz
apache-tomcat-6.0.20.tar.gz
tomcat-connectors-1.2.28-src.tar.gz
jdk-6u17-linux-i586.bin

2,安装apache
tar xzvf httpd-2.2.14.tar.gz
cd httpd-2.2.14
./configure –prefix=/usr/local/apache2 –enable-so
make
make install

3,安装tomcat
tar xzvf apache-tomcat-5.5.12.tar.gz
mv apache-tomcat-5.5.12 /usr/local/tomcat

4,编译生成mod_jk
tar xzvf tomcat-connectors-1.2.28-src.tar.gz
cd cd tomcat-connectors-1.2.28-src/native/
./configure –with-apxs=/usr/local/apache2/bin/apxs
make
cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/

cd /usr/local/apache2/conf
vi mod_jk.conf
# 指出mod_jk模块工作所需要的工作文件workers.properties的位置

JkWorkersFile /usr/local/apache2/conf/workers.properties

# Where to put jk logs

JkLogFile /usr/local/apache2/logs/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”

# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理

JkMount /servlet/* worker1

JkMount /* worker1

vi workers.properties
# Defining a worker named worker1 and of type ajp13

worker.list=worker1

# Set properties for worker1

worker.worker1.type=ajp13

worker.worker1.host=localhost

worker.worker1.port=8009

worker.worker1.lbfactor=50

worker.worker1.cachesize=10

worker.worker1.cache_timeout=600

worker.worker1.socket_keepalive=1

worker.worker1.socket_timeout=300

vi httpd.conf
修改:
DocumentRoot “/var/www”
<Directory “/var/www”>
    Options Includes FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
        XBitHack on
</Directory>
<Directory “/var/www/WEB-INF”>    
        Order deny,allow
        Deny from all
</Directory>

修改:
    DirectoryIndex index.jsp index.html

新增:
    LoadModule jk_module modules/mod_jk.so

  Include /usr/local/apache2/conf/mod_jk.conf

最后编辑Tomcat的配置文件server.xml,在HOST段中加入:

<Context path=”" docBase=”/var/www” debug=”0″ reloadable=”true” crossContext=”true”/>

5,java环境设置
./jdk-6u17-linux-i586.bin
mv jdk1.6.0_17 /usr/local/.

vi /usr/local/tomcat/bin/start.sh
#!/bin/sh
#set java environment
JAVA_HOME=/usr/local/jdk1.6.0_17
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export JAVA_HOME CLASSPATH PATH
/usr/local/tomcat/bin/catalina.sh start

vi /usr/local/tomcat/bin/stop.sh
#!/bin/sh
#set java environment
JAVA_HOME=/usr/local/jdk1.6.0_17
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export JAVA_HOME CLASSPATH PATH
/usr/local/tomcat/bin/catalina.sh stop

chmod 744 start.sh stop.sh

6,运行apache,tomcat
/usr/local/apache2/bin/apachectl start
/usr/local/tomcat/bin/start.sh

7,测试
cd /var/wwwroot
vi index.jsp
<html>
<title>
test jsp
</title>
<%
   String showMessage=”Hello World!”;
   out.print(showMessage);
%>
</html>

访问:http://127.0.0.1

Back Top

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*