前段时间由于测试环境服务器比较紧张,而由于子系统比较多,也由于项目开发测试的要求逼得我们必须想个办法解决这个问题.网上Google了一下,Jboss可以支持多实例处理。有位哥们写的配置指南很详细(http://zzx0421.iteye.com/blog/273261 ),我也是这么配置的。
但是在有一次的配置中,我碰到了问题,发现配置的HTTP端口始终没有生效。就这么说吧,我在一台服务器上配置了4个Jboss实例,发现每个Jboss实例启动的HTTP端口都一样,导致每次只能启动一个jboss实例。后来我去仔细读了bindings.xml 文件,发现在设置http端口的时候有这么一段代码:
<xsl:template match = "Connector">
<Connector>
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="(name() = 'port' and . = '8080')">
<xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'port' and . = '8009')">
<xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'redirectPort')">
<xsl:attribute name="redirectPort"><xsl:value-of select="$portHttps" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'port' and . = '8443')">
<xsl:attribute name="port"><xsl:value-of select="$portHttps" /></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:apply-templates/>
</Connector>
</xsl:template>
上面的代码是XSL语言,可对xml做格式化处理。对应的匹配XML字符串就是server\default\deploy\jboss-web.deployer\server.xml 中结点Connector:
<Service name="jboss.web">
<Connector port="80" address="${jboss.bind.address}"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true"/>
<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />
其他略
</Service>
从XSL模板来看,只有对Connector属性port的值为:8080,8009,8443 三种情况下才采用我们在bindings.xml下设置的端口,否则是把jboss-web.deployer\server.xml 中结点Connector的属性原原本本复制过来,而我在jboss-web.deployer\server.xml 中结点Connector设置的端口为:30080,导致bindings.xml设置的端口无效
<Connector port="30080" address="${jboss.bind.address}"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true"/>
对于zzx0421在http://zzx0421.iteye.com/blog/273261 说的
4. (这个步骤不知道是不是必须的)修改每个jboss服务实例下的Tomcat的配置文件server.xml文件的端口,使其与server-bindings.xml文件中的端口相对应.例如:default下的server.xml中的
<!-- A HTTP/1.1 Connector on port 8080 -->为8081;test下的server.xml中的
<!-- A HTTP/1.1 Connector on port 8080 -->为8888;
这个可以确定的说,不是必须的。只需把端口保持8080不变即可,否则也像我这样悲剧了。