迫于客户需求,搞了一天IIS和tomcat的整合,居然没成功,翻了很多资料,google、baidu都是很旧的文档。终于明白原来这个东西比apache+tomcat简单多了,可能前面折腾乱了,不知道改了什么配置。决定换一个全新的环境,半个小时就搞定了。
鉴于网上文章太旧,包括apache.org上的。发个针对最新版本整合方案出来。
环境:windows 2003 server/IIS 6/tomcat6/isapi_redirect-1.2.8-rc-1.exe
1、首先安装IIS和TOMCAT,略去1000字,保证IIS和tomcat都能独立访问。比如IIS是:http://127.0.0.1。tomcat下应用的访问地址是:http://127.0.0.1:8080/dfz/index.jsp
2、下载tomcat connectors----isapi_redirect-1.2.8-rc-1.exe。apache.org网站上面有,注意不是.dll,如果是.dll还要写注册表配置IIS什么的,麻烦。具体链接没记住。。。但肯定有,慢慢找。如果下载的是dll,那就按照文档办吧。http://tomcat.apache.org/connectors-doc/webserver_howto/iis.html
安装isapi_redirect-1.2.8-rc-1.exe。可以装在默认目录或者自己定义。安装完成后会自动写入注册表并在IIS下建立了一个虚拟目录jakarta,虚拟目录的相关设置都已经做好了,不用动。
3、IIS6下需要手动设置“WEB扩展服务”,添加一个web扩展服务,名称随便写,路径指向安装的连接器的目录C:/Program Files/Apache Software Foundation/Jakarta Isapi Redirector/bin/isapi_redirect.dll。官方文档中的步骤如下:
- If you're using IIS 6.0 you must also do the following:
Using the IIS management console, add the Jakarta Isapi Redirector to the Web Service Extensions. - Right-click on Web Service Extensions and choose Add a new Web Service Extension.
- Enter tomcat for the Extension Name.
- Add the isapi_redirect.dll to the required files.
- Check the Set extension status to Allowed.
- Click on OK.
4、编辑连接器安装目录下的workers.properties.minimal文件,注意:这个跟官方文档有点区别,因为使用的是安装包安装的,注册表里写的是这个配置文件,而不是官方文档的workers.properties,用什么名字都无所谓,关键是注册表对上就可以了。
# workers.properties.minimal -
#
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# The workers that jk should create and work with
#
worker.list=ajp13w
#
# Defining a worker named ajp13w and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13w.type=ajp13
worker.ajp13w.host=localhost
worker.ajp13w.port=8009
安装包已经默认帮你配置了一个worker,如果没有特殊需求,比如LB等,不用动了。性能的优化可以查看apache.org上关于workers.properties的配置,这里不再说了。
5、编辑需要转发内容,uriworkermap.properties
# uriworker.properties -
#
# This file provides sample mappings for example
# ajp13w worker defined in workermap.properties.minimal
/servlet-examples/*=ajp13w
/dfz/*=ajp13w
# Now filter out all .jpeg files inside that context
# For no mapping the url has to start with exclamation (!)
!/servlet-examples/*.jpeg=ajp13w
这里是将servlet-examples和dfz两个目录下的所有内容转发到tomcat执行,前面加有!的意思是不转发符合条件的内容,最后一句就是说不转发jpeg文件。
6、重启IIS,重启tomcat。到这一步,就可以使用IIS访问dfz目录了,比如: http://127.0.0.1/dfz/index.jsp 而tomcat下对应的8080访问地址应该是http://127.0.0.1:8080/dfz/index.jsp
目录问题需要讨论一下,还没时间做测试。IIS下不需要建立任何虚拟目录,会根据uriworkermap.properties转发给tomcat,如果需要jpg之类的文件不转发tomcat,应该就需要建立虚拟目录了。
后话,前天测试出现了一些奇奇怪怪的问题,翻阅大量文档也未能解决。需要排错在注册表里面搜索isapi_redirect.dll,找到log键值,改成debug模式。日志路径在注册表里也能修改。