resin.conf配置详解

 

  1. <!-- - Resin 3.1 配置文件.-->                            

  2. <resin xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core">

  3. <!-- 加载resin/lib下的所有.jar文件-->

  4. <class-loader>

  5. <tree-loader path="${resin.home}/lib"/>

  6. <tree-loader path="${resin.root}/lib"/>

  7. </class-loader>

  8. <!-- - 管理配置 -->                                   

  9. <management path="${resin.root}/admin">

  10. </management>

  11. <!-- -JDK日志接口的配置. -->                              

  12. <log name="" path="stdout:" timestamp="[%H:%M:%S.%s] "/>

  13. <!-- 日志信息的级别:'info' 生产环境 'fine' 开发环境 'finer' 调试环境 -->

  14. <logger name="com.caucho" level="info"/>

  15. <logger name="com.caucho.java" level="config"/>

  16. <logger name="com.caucho.loader" level="config"/>

  17. <!-- - 环境上下文的检测时间,对于生产站点, 这个要设置长一点,例如600秒,10分钟 -->

  18. <dependency-check-interval>2s</dependency-check-interval>

  19. <!-- - 发送邮件通知的SMTP服务器 -->

  20. <system-property mail.smtp.host="127.0.0.1"/>

  21. <system-property mail.smtp.port="25"/>

  22. <!-- - 你可以把编译器改成 "javac", "eclipse" 或者 "internal". -->      

  23. <javac compiler="internal" args="-source 1.5"/>

  24. <!-- Security providers.

  25. - <security-provider>

  26. - com.sun.net.ssl.internal.ssl.Provider

  27. - </security-provider>

  28. -->

  29. <!-- 去掉注释,如果你使用resin提供的xml应用

  30. -

  31. - <system-property javax.xml.parsers.DocumentBuilderFactory

  32. - ="com.caucho.xml.parsers.XmlDocumentBuilderFactory"/>

  33. - <system-property javax.xml.parsers.SAXParserFactory

  34. - ="com.caucho.xml.parsers.XmlSAXParserFactory"/>

  35. -->

  36. <cluster id="app-tier">

  37. <!-- 设置集群上下文的根, 相对于server.root -->

  38. <root-directory>.</root-directory>

  39. server实例                                           

  40. <server-default>

  41. <!-- HTTP服务的端口-->                                    

  42. <http address="*" port="8080"/>

  43. <!--

  44. - SSL端口配置:

  45. -

  46. - <http address="*" port="8443">

  47. - <openssl>

  48. - <certificate-file>keys/gryffindor.crt</certificate-file>

  49. - <certificate-key-file>keys/gryffindor.key</certificate-key-file>

  50. - <password>test123</password>

  51. - </openssl>

  52. - </http>

  53. -->

  54. <!-- - JVM参数设置 -->

  55. <jvm-arg>-Xmx256m</jvm-arg>

  56. <jvm-arg>-Xss1m</jvm-arg>

  57. <jvm-arg>-Xdebug</jvm-arg>

  58. <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

  59. <!-- Uncomment to enable admin heap dumps 去掉这个如果你想管理内存堆的倾倒

  60. - <jvm-arg>-agentlib:resin</jvm-arg>

  61. -->

  62. <watchdog-arg>-Dcom.sun.management.jmxremote</watchdog-arg>

  63. <!-- 强制resin强制重起时的最小空闲内存 -->

  64. <memory-free-min>1M</memory-free-min>

  65. <!-- 最大线程数量. -->

  66. <thread-max>256</thread-max>

  67. <!-- 套接字等待时间 -->

  68. <socket-timeout>65s</socket-timeout>

  69. <!-- 配置 keepalive -->

  70. <keepalive-max>128</keepalive-max>

  71. <keepalive-timeout>15s</keepalive-timeout>

  72. <!-- - 如果使用的是UNIX,这里是启动的帐号和用户组.

  73. - <user-name>resin</user-name>

  74. - <group-name>resin</group-name>

  75. -->

  76. </server-default>


  77. <!-- 定义群集服务器 -->                                     

  78. <server id="" address="127.0.0.1" port="6800"/>

  79. <!-- Configures the persistent store for single-server or clustered 配置独立服务器或者群集的持久化存储,专业版的功能 -->

  80. <resin:if test="${resin.isProfessional()}">

  81. <persistent-store type="cluster">

  82. <init path="session"/>

  83. </persistent-store>

  84. </resin:if>

  85. <!-- 为了安全, 你可以为SSL会话(SSL sessions)定义一个不同的cookie.

  86. - <ssl-session-cookie>SSL_JSESSIONID</ssl-session-cookie>

  87. -->

  88. <!-- 缓存启用 (专业版的功能) -->

  89. <resin:if test="${isResinProfessional}">

  90. <cache path="cache" memory-size="64M">

  91. <!-- Vary header rewriting for IE -->

  92. <rewrite-vary-as-private/>

  93. </cache>

  94. </resin:if>

  95. <!-- 启用周期性的服务器状态检查和死锁检查,所有的服务器可以添加 <url> 来检查。 -->

  96. <resin:if test="${isResinProfessional}">

  97. <ping>

  98. <!-- <url>http://localhost:8080/test-ping.jsp</url> -->

  99. </ping>

  100. </resin:if>

  101. <!-- 包含web应用的默认行为 -->

  102. <resin:import path="${resin.home}/conf/app-default.xml"/>

  103. <!-- 每一个web应用的默认参数 -->

  104. <web-app-default>

  105. <!-- 扩展库的公共jar文件,扩展是安全的即使没有类装载器知道的jars,装载的类将为每个应用分别装载,也就是这些类都是不同的 -->

  106. <class-loader>

  107. <tree-loader path="${server.root}/ext-webapp"/>

  108. </class-loader>

  109. <!-- 设置缓存页、静态也的延时值 -->

  110. <cache-mapping url-pattern="/" expires="5s"/>

  111. <cache-mapping url-pattern="*.gif" expires="60s"/>

  112. <cache-mapping url-pattern="*.jpg" expires="60s"/>

  113. <cache-mapping url-pattern="*.png" expires="60s"/>

  114. <!-- 启用EL表达式 -->

  115. <allow-servlet-el/>

  116. <!-- 安全原因, 默认禁用了会话的URLs -->

  117. <session-config>

  118. <enable-url-rewriting>false</enable-url-rewriting>

  119. </session-config>

  120. <!-- 安全原因, 在cookies中设置HttpOnly标志

  121. - <cookie-http-only/>

  122. -->

  123. <!--一些JSP包有不正确的 .tld文件。可以把validate-taglib-schema设置成false,可能继续正常工作

  124. - Some JSP packages have incorrect .tld files. It's possible to set validate-taglib-schema to false to work around these packages.

  125. -->

  126. <jsp>

  127. <validate-taglib-schema>true</validate-taglib-schema>

  128. <fast-jstl>true</fast-jstl>

  129. <fast-jsf>true</fast-jsf>

  130. </jsp>

  131. </web-app-default>

  132. <!-- 简单的数据池配置

  133. - The JDBC name is java:comp/env/jdbc/test

  134. <database>

  135. <jndi-name>jdbc/mysql</jndi-name>

  136. <driver type="org.gjt.mm.mysql.Driver">

  137. <url>jdbc:mysql://localhost:3306/test</url>

  138. <user></user>

  139. <password></password>

  140. </driver>

  141. <prepared-statement-cache-size>8</prepared-statement-cache-size>

  142. <max-connections>20</max-connections>

  143. <max-idle-time>30s</max-idle-time>

  144. </database>

  145. -->

  146. <!-- 定义所有虚拟主机的默认配置 -->

  147. <host-default>

  148. <!-- 如果和别的web服务器整合,这个可以被去掉,因为web服务器也可以记录这些信息。 -->

  149. <access-log path="logs/access.log" format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/>

  150. <!-- war 文件的布置目录 -->

  151. <web-app-deploy path="webapps"/>

  152. <!-- ear文件的布置目录 -->

  153. <ear-deploy path="deploy">

  154. <ear-default>

  155. <ejb-server>

  156. <config-directory>WEB-INF</config-directory>

  157. <data-source>jdbc/test</data-source>

  158. </ejb-server>

  159. </ear-default>

  160. </ear-deploy>

  161. <!-- rar文件的布置目录 -->

  162. <resource-deploy path="deploy"/>

  163. </host-default>

  164. <!-- 虚拟主机的布置目录 -->

  165. <host-deploy path="hosts">

  166. <host-default>

  167. <resin:import path="host.xml" optional="true"/>

  168. </host-default>

  169. </host-deploy>

  170. <!-- 默认的虚拟主机配置 -->                                   

  171. <host id="" root-directory=".">

  172. <!-- 配置默认的应用 webapp's ROOT -->

  173. <web-app id="/" root-directory="webapps/ROOT"/>

  174. <web-app id="/resin-admin" root-directory="${resin.home}/php/admin">

  175. <!-- - 管理应用程序 /resin-admin

  176. - password is the md5 hash of the password。md5码的密码。

  177. - localhost is true to limit access to the localhost。localhost设置成true,这样只有localhost才能访问

  178. -->

  179. <prologue>

  180. <resin:set var="resin_admin_user" value=""/>

  181. <resin:set var="resin_admin_password" value=""/>

  182. <resin:set var="resin_admin_external" value="false"/>

  183. </prologue>

  184. </web-app>

  185. </host>


  186. </cluster>

  187. <!-- - Configuration for the web-tier/load-balancer -->

  188. <resin:if test="${resin.isProfessional()}">

  189. <cluster id="web-tier">

  190. <server-default>

  191. <!-- The http port -->

  192. <http address="*" port="9080"/>

  193. </server-default>

  194. <server id="web-a" address="127.0.0.1" port="6700"/>

  195. <cache path="cache" memory-size="64M"/>

  196. <host id="">

  197. <web-app id="/">

  198. <rewrite-dispatch>

  199. <load-balance regexp="" cluster="app-tier"/>

  200. </rewrite-dispatch>

  201. </web-app>

  202. </host>

  203. </cluster>

  204. </resin:if>

  205. </resin>


关键配置解释:

  1. 3.1 数据库连接池配置

  2. 如果应用使用数据库连接池,查找<caucho.com>,在其后加入数据库连接池的配置信息如下:

  3. SQL SERVER

  4. ==================================================================

  5. <resource-ref>

  6. <res-ref-name>jdbc/job36_use</res-ref-name>

  7. <res-type>javax.sql.DataSource</res-type>

  8. <init-param driver-name="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>

  9. <init-param url="jdbc:microsoft:sqlserver://192.168.3.84:1433;create=true;DatabaseName=CRM"/>

  10. <init-param user="sa"/>

  11. <init-param password="job36"/>

  12. <init-param max-connections="10"/>

  13. <init-param enable-transaction="true"/>

  14. </resource-ref>


  15. ORACLE

  16. ==================================================================

  17. <resource-ref>

  18. <res-ref-name>jdbc/job36</res-ref-name>

  19. <res-type>javax.sql.DataSource</res-type>

  20. <init-param driver-name="oracle.jdbc.driver.OracleDriver"/>

  21. <init-param url="jdbc:oracle:thin:@192.168.3.84:1521:CRM"/>

  22. <init-param user="job36"/>

  23. <init-param password="job36"/>

  24. <init-param max-connections="10"/>

  25. <init-param enable-transaction="false"/>

  26. </resource-ref>

  27. 注意:如果要访问数据库,请先确认RESIN安装目录下lib文件夹有相应数据库的JDBC驱动,如mssqlserver.jar或oracle_jdbc.jar等,否则请先将驱动文件拷贝到该目录,不然无法访问数据库。

  28. <res-ref-name>字段为连接池名字,要与业务应用配置相同;

  29. <init-param url>字段为数据库连接字符串,蓝色部分为数据库服务器IP:PORT、数据库名或SID。<init-param user>数据库用户名。

  30. <init-param password>密码。

  31. <init-param max-connections>字段为连接池最大连接个数,这个数据对基于WEB的数据库应用性能有一定影响,建议配置数为10~40(数据库应用较多时配置应偏小,网页应用较多时应偏大)。


  32. 3.2 服务端口配置

  33. 查找<http port='8080'/>,蓝色字符串即为端口号,根据实际应用修改。

  34. 如果需要在一台服务器上启动多个resin服务,请按相应规划各应用端口号在每个resin安装目录的配置文件中配置该项,不可重复。


  35. 3.3 更新类间隔时间

  36. <class-update-interval>60s</class-update-interval>,蓝色字符为配置项,单位为秒。

  37. Class-update-interval字段对RESIN服务性能影响较大,请根据需求更改,建议配置原则为:在开发环境,设为2或更小,这样有利于 及时反映程序的修改对应用造成的改变;生产环境建议配置最小60,根据生产环境的特点,不可能有频繁的类改动或是JAVA脚本改变,或者根本不会有改动, 所以依据实际情况,设置为60~3600。


  38. 3.4 最大进程数

  39. <thread-max>20</thread-max>,蓝色字符为配置项。

  40. Thread-max字段为RESIN服务最大接收处理的进程个数,为了达到较好的性能输出,建议该项配置值为3.1连接池中max-connections参数的1倍。即,如果连接池max-connections设为10,那么就将thread-max设为20。

  41. #resin.3.1版本安装之后默认是1024,我改成了1024*20=20480.(zixun)

  42. 3.5 保持活动进程数

  43. <thread-keepalive id='19'/>,蓝色字符为配置项。

  44. Thread-keepalive字段为RESIN服务保持链接活动性的最大个数,它的值一定要小于3.4节中thread-max的值,否则RESIN无法启动。该项无建议值。


  45. 3.6 请求超时时长

  46. <request-timeout id='65s'/>,蓝色字符为配置项,单位为秒。

  47. Request-timeout字段为RESIN服务返回请求链接超时的时间,默认即可。


  48. 3.7 接收链接缓冲大小

  49. <accept-buffer-size id='500'/>,蓝色字符为配置项。

  50. Accept-buffer-size id字段为RESIN服务在满进程数下接收等待进程缓冲的个数,根据服务器、网络情况而定,无建议值。


  51. 3.8 缓存文件过期时间

  52. <cache-mapping url-pattern='/' expires='2s'/>,蓝色字符为配置项。

  53. RESIN运行中把被访问文件数据进行缓存(默认缓存目录为RESIN安装目录下的cache目录,可在<cache dir='cache' size='1024' entries='8192'/>字段修改为指定路径),以便更加有效率的工作,Cache-mapping url-pattern字段为RESIN服务保持缓存文件有效性的时间,开发环境推荐配置为默认值2,生产环境建议配置较大值,比如15或30。本配置基 于应用,增加缓存有效时间,在有较多相同页面服务时减少了服务器的业务逻辑,转而利用磁盘缓冲文件提供数据;但是如果在固定时间长度里(比如10分钟)相 同页面的请求率很小或甚至没有相同的请求时,会增加一次缓存文件匹配动作,反而降低了服务器效率。因此,在特殊的应用中,可以将本配置项设为2,或注 释<cache dir='cache' size='1024' entries='8192'/>,取消缓存功能。


  54. 3.9 虚拟主机设置


  55. 3.9.1 默认文档设置

  56. <welcome-file-list>index.xtp, index.jsp, index.html</welcome-file-list>.

  57. Wecome-file-list字段为默认文档的文件列表。默认文档是在客户端访问Web服务器,比如RESIN,时如果没有制定要访问的文件(即输入 URL为目录名而不是具体的文件名,如:http://localhost:8080/),此时RESIN会根据该字段的值来搜索URL访问目录查找匹配 文件,如果找到文件则返回给用户而不需用户输入全部的URL,比如:http://localhost:8080/index.html。

  58. 该配置项一般用来设置默认主页。


  59. 3.9.2 主机ID

  60. <host id=''>.

  61. Host id字段在单主机环境、一台服务器需要启动多个不同的RESIN服务时不用配置,请保持默认的空值。只有当与其他web服务器,比如apache等,同时使用时,考虑改配置项。


  62. 3.9.3 日志

  63. <!--access-log id='logs/access.log'

  64. format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'

  65. rollover-period='1W'/-->

  66. <error-log id='logs/error.log'/>,蓝色字符为配置项。

  67. ? access-log id字段为RESIN记录运行时访问日志,该日志在单独服务器情况下不推荐使用,就算在混合服务器情况下(比如IIS、APACHE等)也不推荐,除非要分析个服务器的访问情况。如果不使用注释该段即可(加入红色部分代码)。

  68. ? error-log id字段为RESIN错误日志,建议使用默认值。日志保存在RESIN安装目录的logs文件夹里。


  69. 3.9.4 虚拟目录

  70. 在<host></host>字段中加入<web-app id='/test’ app-dir='C:\webapp'/>,蓝色字符为配置项。

  71. Web-app id字段为RESIN虚拟目录名,app-dir字段为本地路径值。

  72. 例如:上面的配置实现了将http://localhost:8080/test/ 映射到了服务器本地的c:\webapp目录,该目录内容应为web应用的代码或脚本。