Tomcat6&IIS整合,6小时实践成功

 

大体上是别人的流程  我是在它的基础上 实践成功了, 较之以前的有部分修改和补充 使得更容易理解。 

 

IIS+TomcatIIS80端口)。配置相对简单,但效率一般,适合一般性应用。这里所讲的是后者的模式。此外,对于后者,也有两种实现方式,一是通过JK2实现IISTomcat的连接,这种方式前一段时间比较流行,但Apache组织已经宣布其对JK2停止更新;另一种是通过JK实现,该连接器Apache还将一直更新。这里讲JK实现。

1、安装IISTomcat
     
安装IIS:打开控制面板,添加删除程序,添加/删除Windows组件,选中应用程序服务器并安装。安装过程中需要Windows2003的原始安装文件。如果实在没有,可以在网上下载一个IIS6.0的安装包即可。这里提供一个下载地址:http://www.f989.com/Html/download/sys/18073992.html

 安装Tomcat:这个没什么要说的,就用8080端口,再就是建议不要装在默认位置,最好装在其它盘的根目录下。这里假设装载F:\Tomcat下。Tomcat的最新版下载地址:http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.exe


2、在Tomcat中建立项目站点------我这里做的是直接将root用了,把项目文件拷贝到root
     

 

3、配置Tomcatserver.xml
     
打开F:\Tomcat\conf\server.xml,把下面的内容插入到<Engine></Engine>之间

       <Host name="localhost"   appBase="webapps"
             unpackWARs="true" autoDeploy="true"
             xmlValidation="false" xmlNamespaceAware="false">
       </Host>

     注意,其中name属性指主机名,即这个站点对应的域名,appBase属性指站点所在位置。
     
保存后重新启动Tomcat,这时打开ie浏览器,输入http://127.0.0.1:8080

我的例子:server.xml

<?xml version='1.0' encoding='utf-8'?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  this work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0

  (the "License"); you may not use this file except in compliance with

  the License.  You may obtain a copy of the License at

 

      http://www.apache.org/licenses/LICENSE-2.0

 

  Unless required by applicable law or agreed to in writing, software

  distributed under the License is distributed on an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

-->

<!-- Note:  A "Server" is not itself a "Container", so you may not

     define subcomponents such as "Valves" at this level.

     Documentation at /docs/config/server.html

 -->

<Server port="8005" shutdown="SHUTDOWN">

 

  <!--APR library loader. Documentation at /docs/apr.html -->

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->

  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

 

  <!-- Global JNDI resources

       Documentation at /docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    <Resource name="UserDatabase" auth="Container"

              type="org.apache.catalina.UserDatabase"

              description="User database that can be updated and saved"

              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

              pathname="conf/tomcat-users.xml" />

  </GlobalNamingResources>

 

  <!-- A "Service" is a collection of one or more "Connectors" that share

       a single "Container" Note:  A "Service" is not itself a "Container",

       so you may not define subcomponents such as "Valves" at this level.

       Documentation at /docs/config/service.html

   -->

  <Service name="Catalina">

 

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->

   

   

    <!-- A "Connector" represents an endpoint by which requests are received

         and responses are returned. Documentation at :

         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)

         Java AJP  Connector: /docs/config/ajp.html

         APR (HTTP/AJP) Connector: /docs/apr.html

         Define a non-SSL HTTP/1.1 Connector on port 8080

    -->

    <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <!-- A "Connector" using the shared thread pool-->

    <!--

    <Connector executor="tomcatThreadPool"

               port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    -->          

    <!-- Define a SSL HTTP/1.1 Connector on port 8443

         This connector uses the JSSE configuration, when using APR, the

         connector should be using the OpenSSL style configuration

         described in the APR documentation -->

    <!--

    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

               maxThreads="150" scheme="https" secure="true"

               clientAuth="false" sslProtocol="TLS" />

    -->

 

    <!-- Define an AJP 1.3 Connector on port 8009 -->

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

 

 

    <!-- An Engine represents the entry point (within Catalina) that processes

         every request.  The Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to the appropriate Host (virtual host).

         Documentation at /docs/config/engine.html -->

 

    <!-- You should set jvmRoute to support load-balancing via AJP ie :

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">        

    -->

    <Engine name="Catalina" defaultHost="localhost">

 

      <!--For clustering, please take a look at documentation at:

          /docs/cluster-howto.html  (simple how to)

          /docs/config/cluster.html (reference documentation) -->

      <!--

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      -->       

 

      <!-- The request dumper valve dumps useful debugging information about

           the request and response data received and sent by Tomcat.

           Documentation at: /docs/config/valve.html -->

      <!--

      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>

      -->

 

      <!-- This Realm uses the UserDatabase configured in the global JNDI

           resources under the key "UserDatabase".  Any edits

           that are performed against this UserDatabase are immediately

           available for use by the Realm.  -->

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

             resourceName="UserDatabase"/>

 

      <!-- Define the default virtual host

           Note: XML Schema validation will not work with Xerces 2.2.

       -->

      <Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true"

            xmlValidation="false" xmlNamespaceAware="false">

 <Context path="" docBase="/tingting" debug="0" reloadable="true" crossContext="true"/>

    <!tingting为项目名称-à

        <!-- SingleSignOn valve, share authentication between web applications

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

        -->

 

        <!-- Access log processes all example.

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 

               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

        -->

 

      </Host>

    </Engine>

  </Service>

</Server>

 

 


4、配置连接器
     
去下载JK连接器,下载地址:
    http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.25/isapi_redirect.dll
     
把这个dll文件拷贝到F:\Tomcat\conf下。
     
然后在F:\Tomcat\conf内新建uriworkermap.propertiesworkers.properties两个文件,文件内容分别为:

uriworkermap.properties中配置要过滤的请求 一般是/*.do=ajp13
     uriworkermap.properties

/*.*=ajp13
/*=ajp13

/*.do=ajp13

 

 

以下文件中配置链接关系

     workers.properties

workers.tomcat_home=F:\Tomcat       #tomcat的安装目录
workers.java_home=F:\Program Files\Java\jdk1.6.0   #Java
虚拟机目录
ps=\  #
不可省略
worker.list=ajp13
worker.ajp13.port=8009 
worker.ajp13.host=localhost  #
你的域名,不填则通过ip可以访问,一般学习不填
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

     注意,这样写两个配置文件,解决了servlet打不开的问题。workers.tomcat_hometomcat的安装位置,workers.java_homejdk所在位置。
     
然后随便在哪新建一个jakarta.reg文件,内容为:

Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0] 
"log_file"="F:\\Tomcat\\logs\\isapi.log" 
"log_level"="debug" 
"worker_file"="F:\\Tomcat\\conf\\workers.properties" 
"worker_mount_file"="F:\\Tomcat\\conf\\uriworkermap.properties" 

#如果没有tomcat.bat 则不用写这个语句

"tomcat_start"="F:\\Tomcat\\bin\\tomcat.bat start" "tomcat_stop"="F:\\Tomcat\\bin\\tomcat.bat stop" 
"extension_uri"="/jakarta/isapi_redirect.dll"

其中jakartal不可省略 他对应与后面IIS中的虚拟目录。

     注意修改其中你的Tomcat安装位置。然后执行这个文件,把上述内容导入注册表!

5、在IIS中添加JSP站点
     
IIS中新建一个站点,描述随便填,关键在于下面这个窗口:



 端口都用80IP也可以就填全部未分配,最关键的就在于此网站主机头信息,注意要和Tomcatserver.xml文件中对应。主目录选到对应的项目。权限把读取运行脚本都钩上。
     
然后,在该站点下新建一个虚拟目录,别名叫jakarta,路径选到F:\Tomcat\conf  (isapi_redirect.dll所在的文件夹),千万记住权限把执行钩上。
     
然后打开该网站的属性,进入ISAPI筛选器选项卡,点击添加,筛选器名称填写jakarta,可执行文件选到F:\Tomcat\conf\isapi_redirect.dll

Jakarta中属性 ---》虚拟目录---》配置---》过滤类型eg:.do,.jsp.可执行文件选择isapi_redirect.dll.
    
6、添加IISWeb服务扩展
     
打开IIS,在“Web服务扩展上点又键,添加一个Web服务扩展。扩展名填写jakarta,添加一个要求的文件,选到F:\Tomcat\conf\isapi_redirect.dll,把设置扩展状态为允许钩上。

7、修改域名解析(一般学习没有使用)
     
去你域名的DSN管理系统,把域名解析到你的服务器上

8、重启服务
     
重新启动你的IIS服务,注意,是IIS服务,不是站点!重新启动你的Tomcat

在运行是 tomcatIIS都必须打开。

     OK,大功告成!当然了,配置过程中,难免出现这样那样的异常,但没关系,仔细地研究一下,你会进步更多的!
     
如果还需要PHP支持,看看网上IIS整合PHP就行了。这样以IIS负责虚拟主机的解析,应该是大家都所熟悉的,所以会比Apache简单得多。

      如果发现JSP网站还是不能正常打开的话,一般是由于Windows 2003的权限问题,记住,一定要给Tomcat所在文件夹完全控制的权限。

  

 

经过6个小时奋战 终于搞定   悲剧的很font-

分享到:
评论

猜你喜欢

转载自wptc.iteye.com/blog/684979