Linux 下Apache 和Tomcat 整合 mod_jk

apache-tomcat-7.0.6.tar.gz

httpd-2.2.17.tar.gz

jdk-6u23-linux-i586.bin

tomcat-connectors-1.2.31-src.tar.gz

1.安装httpd

tar zxvf httpd-2.2.17.tar.gz
cd httpd-2.2.17
./configure --prefix=/usr/local/apache2 --enable-so
make && make install

2.安装JDK

chmod +x jdk-6u18-linux-i586.bin
./jdk-6u18-linux-i586.bin
mv jdk1.6.0_18 /usr/local/jdk
rm -rf /usr/bin/java
rm -rf /usr/bin/javac
ln -s /usr/local/jdk/bin/java /usr/bin/java
ln -s /usr/local/jdk/bin/javac /usr/bin/javac

[root@CentOSlamp src]# java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

ln -s /usr/local/jdk/jre /usr/local/jre

设置环境变量

vi /etc/profile 添加如下内容

JAVA_HOME=/usr/local/jdk
export JAVA_HOME
JRE_HOME=/usr/local/jre
export JRE_HOME

运行,使环境变量生效

source /etc/profile

3.安装tomcat

tar zxvf apache-tomcat-7.0.6.tar.gz
mv apache-tomcat-7.0.6 /usr/local/tomcat

4.安装tomcat-connectors

tar zxvf tomcat-connectors-1.2.31-src.tar.gz

cd tomcat-connectors-1.2.31-src/native/

./configure --with-apxs=/usr/local/apache2/bin/apxs --with-java-home=/usr/local/jdk
make && make install

5. 配置httpd.conf 文件

vi /usr/local/apache2/conf/httpd.conf

添加

LoadModule jk_module modules/mod_jk.so

<IfModule jk_module>
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
</IfModule>

6.创建并配置workers.properties文件

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

worker.list=wlb , jkstatus
worker.ajp13w.type=ajp13
worker.ajp13w.host=localhost
worker.ajp13w.port=8009
worker.wlb.type=lb
worker.wlb.balance_workers=ajp13w

worker.jkstatus.type=status

7.创建并配置uriworkermap.properties

vi /usr/local/apache2/conf/uriworkermap.properties

/admin/*=wlb
/manager/*=wlb
/jsp-examples/*=wlb
/servlets-examples/*=wlb
/examples/*=wlb
/*.jsp=wlb
!/servlets-examples/*.jpeg=wlb

/jkmanager=jkstatus

8.编辑server.xml文件

vi /usr/local/tomcat/conf/server.xml

在这个位置修改

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/usr/local/apache2/htdocs" debug="0"/>

 

9.在/usr/local/apache2/htdocs下创建测试文件test.jsp

vi /usr/local/apache2/htdocs/test.jsp

<%
    System.out.println( "Evaluating date now" );
    java.util.Date date = new java.util.Date();
%>
Hello!  The time is now <%= date %>

 

10.启动tomcat 和httpd 服务

[root@www src]# /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/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

/usr/local/apache2/bin/apachectl restart

11.测试

访问http://192.168.15.124/test.jsp 时输出

Hello! The time is now Sun Jan 30 13:55:23 CST 2011

http://192.168.15.124/jkmanager 可以查看状态

JK Status Manager for 192.168.15.124:80

相关推荐