1.主要软件准备
下载JDK、Tomcat、Apache server、Tomcat connector
本教程中分别为jdk1.6、Tomcat 6.0.13、apache_2.2.4-win32-x86-no_ssl、mod_jk-apache-2.2.4.so
2.安装配置JDK、Tomcat,安装Apache
这个网上教程很多,主要是设置一些环境变量
本教程中JAVA_HOME=D:/Program Files/Java/jdk1.6.0
TOMCAT_HOME=D:/Program Files/Apache Software Foundation/Tomcat 6.0
APACHE_HOME=D:/Program Files/Apache Software Foundation/Apache2.2
后面涉及到安装路径时用%XXX_HOME%代替
3.把Tomcat Connector拷贝到%APACHE_HOME%/models/目录
在Apacehe主页上找到Tomcat Connectors下载地址(http://tomcat.apache.org/download-connectors.cgi)
目前最新的是mod_jk-apache-2.2.4.so,然后拷贝到%APACHE_HOME%/models/目录下
4.在%APACHE_HOME%/conf/目录下新建workers.properties文件
内容为:
#以下为workers.propertie的内容
worker.list=loadbalancer,server105,server106
# Define the first node...
worker.server105.port=8009
worker.server105.host=127.0.0.1
worker.server105.type=ajp13
worker.server105.lbfactor=1
#worker.server105.local_worker=1
worker.server105.cachesize=100
# Define the 2nd node...
worker.server106.port=8009
worker.server106.host=127.0.0.1
worker.server106.type=ajp13
worker.server106.lbfactor=1
#worker.server106.local_worker=1
worker.server106.cachesize=100
# Now we define the load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=server105,server106
worker.loadbalancer.sticky_session=1
5.修改%APACHE_HOME%/conf/httpd.conf文件
1)找到<IfModule dir_module>标签
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
把DirectoryIndex index.htm 改为DirectoryIndex index.html index.htm index.jsp
2)找到DocumentRoot变量
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
把DocumentRoot修改为Tomcat的默认根目录,即%TOMCAT_HOME%/webapps/ROOT. x修改后结果如下:
DocumentRoot "D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT"
注意: 这里使用了url路径格式,用"/"代替了系统文件路径中的"/"
3)找到<Directory>标签。可以找到很多,呵呵。注意标签上面的注释
"把值修改为DocumentRoot变量值"
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
修改后结果如下
<Directory "D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT">
注意: 这里使用了url路径格式,用"/"代替了系统文件路径中的"/"
4)
在httpd.conf最后加上如下内容,主要是和Tomcat完成任务分配
############################下面为增加的内容############################
LoadModule jk_module modules/mod_jk-apache-2.2.4.so #这里要和下载的connector的名字一致
[加到LoadModule的模块位置,否则有可能出错!!!!]
JkWorkersFile conf/workers.properties #这里要和第三步新建的属性文件名字一致
JkLogFile logs/mod_jk.log #日志保存在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 /* loadbalancer
JkMount /xajob/* loadbalancer
#apache will serve the static picture.
#以下命令意味着所有的图片将由APACHE解析
JkUnMount /*.jpg loadbalancer
JkUnMount /*.gif loadbalancer
JkUnMount /*.swf loadbalancer
JkUnMount /*.bmp loadbalancer
JkUnMount /*.png loadbalancer
6.重启Tomcat和Apache Server
如果使用http://localhost:8080 与http://localhost均能看到tomcat
默认页面,那么恭喜你配置成功了。
注意:本教程tomcat使用默认8080端口,apache作为系统服务安装使用了80端口
如果你使用了不同端口,根据实际情况在路径后添加自己设定端口号就好