Running multiple instances of Jboss on one server.

To run multiple Jboss instances on the one server is pretty easy – but remember that if you’re running something like ATG commerce you’re going to need a few Gb...

To run multiple Jboss instances on the one server is pretty easy – but remember that if you’re running something like ATG commerce you’re going to need a few Gb of memory to run just the one JBoss instance let alone multiples. So you may want seriously consider keeping separate VM’s for each server in your production environment depending on your application requirements e.g for heavyweight commerce keep them all as separate as possible. But for quickly building a development environment this is the way to go.

Anyway, the main thing to worry about with JBoss is the network ports setting as each instance needs it’s own port range, once you’ve done this then it’s all down to your application as to which port set it needs to use. So here’s how to set multiple instances and their respective ports. You’ll see that most if not all config for JBoss is done with XML files.

First we need to create an XML file to store our port bindings, thankfully we can use a sample one which you’ll find in: jboss\docs\examples\binding-manager\sample-bindings.xml and we can create a new directory to store this, something like jboss\bindings\binding.xml

You can see below a section of the code which sets up a ports definition for our server. At most I have done 4 configurations and actively run them all at once on a machine with 3Gb memory and it worked fine for my development requirements. Also I would recommend that you only use 1 bindings file however you can create and use multiple XML’s. Also you will see that we’re using ports 8180 instead of the typical 8080, this potentially leaves you 8080 free for another server giving you 5 in total – or it leaves the ports free if you need to map in an additional server on 8080, like FatWire. Depends on your architecture really, just remember 8080 is the default port setting of JBoss.

<service-bindings>
 
   <!-- ********************************************************** -->
   <!-- *                          ports-01                      * -->
   <!-- ********************************************************** -->
   <server name="[SERVER NAME]">
 
      <!-- EJB3 Remoting Connector ejb3.deployer/META-INF/jboss-service.xml -->
 
      <service-config name="jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
        <delegate-config>
           <attribute name="InvokerLocator">socket://${jboss.bind.address}:3973</attribute>
        </delegate-config>
         <binding port="3973"/>
      </service-config> <!-- Can also be 4073, 4173, 4273 -->
 
      <!-- ********************* jboss-service.xml ****************** -->
 
      <service-config name="jboss:service=Naming"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="Port" hostName="BindAddress">
            <attribute name="RmiPort">1198</attribute> <!-- Can also be 1298, 1398, 1498 -->
         </delegate-config>
         <binding port="1199" host="${jboss.bind.address}"/> <!-- Can also be 1299, 1399, 1499 -->
      </service-config>
 
      <service-config name="jboss:service=WebService"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="Port"/>
         <binding port="8183"/> <!-- Can also be 8283, 8383, 8483 -->
      </service-config>
 
      <service-config name="jboss:service=invoker,type=jrmp"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="RMIObjectPort"/>
         <binding port="4544"/> <!-- Can also be 4644, 4744, 4844 -->
      </service-config>
 
      <service-config name="jboss:service=invoker,type=pooled"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="ServerBindPort"/>
         <binding port="4545"/> <!-- Can also be 4645, 4745, 4845 -->
      </service-config>
 
      <!-- ********************* cluster-service.xml **************** -->
 
      <service-config name="jboss:service=HAJNDI"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="Port" hostName="BindAddress">
            <attribute name="RmiPort">1201</attribute> <!-- Can also be 1301, 1401, 1501 -->
         </delegate-config>
         <binding port="1200" host="${jboss.bind.address}"/> <!-- Can also be 1300, 1400, 1500 -->
      </service-config>
 
      <service-config name="jboss:service=invoker,type=jrmpha"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="RMIObjectPort"/>
         <binding port="4544"/> <!-- Can also be 4644, 4744, 4844 -->
      </service-config>
 
      <service-config name="jboss:service=invoker,type=pooledha"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="ServerBindPort"/>
         <binding port="4546"/> <!-- Can also be 4646, 4746, 4846 -->
      </service-config>
 
      <!-- ********************* iiop-service.xml ****************** -->
 
      <service-config name="jboss:service=CorbaORB"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="Port"/>
         <binding port="3628"/> <!-- Can also be 3728, 3828, 3928 -->
      </service-config>      
 
      <!-- ********************* jmx-rmi-adaptor.sar **************** -->
 
      <service-config name="jboss.jmx:type=Connector,name=RMI"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="RMIObjectPort"/>
         <binding port="19101"/> <!-- Can also be 19201, 19301, 19401 -->
      </service-config>
 
      <!-- ********************* snmp-adaptor.sar ****************** -->
 
      <service-config name="jboss.jmx:name=SnmpAgent,service=trapd,type=logger"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="Port"/>
         <binding port="1262"/> <!-- Can also be 1362, 1462, 1562 -->
      </service-config>
 
      <service-config name="jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="Port"/>
         <binding port="1261"/> <!-- Can also be 1361, 1461, 1561 -->
      </service-config>
 
      <!-- ********************* jbossmq-service.xml **************** -->
 
      <!-- JMS related services -->
      <service-config name="jboss.mq:service=InvocationLayer,type=UIL2"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="ServerBindPort"/>
         <binding port="8193"/> <!-- Can also be 8293, 8393, 8493 -->
      </service-config>
 
      <!-- ********************* jbossmq-httpil.sar **************** -->
      <service-config name="jboss.mq:service=InvocationLayer,type=HTTP"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config portName="URLPort"/>
         <binding port="8180"/> <!-- Can be 8280, 8380, 8480 -->
      </service-config>
 
      <!-- ********************* hajndi-jms-ds.xml **************** -->
 
      <!-- The JMS provider loader -->
      <service-config name="jboss.mq:service=JMSProviderLoader,name=HAJNDIJMSProvider"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <!-- 
              MAKE SURE java.naming.provider.url 
              PORT IS SAME AS HA-JNDI ABOVE !!!
         -->
         <delegate-config>
            <attribute name="Properties"><![CDATA[
                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                java.naming.provider.url=${jboss.bind.address:localhost}:1200 <!-- Can also be 1300, 1400, 1500 -->
                jnp.disableDiscovery=false
                jnp.partitionName=${jboss.partition.name:DefaultPartition}
                jnp.discoveryGroup=${jboss.partition.udpGroup:230.0.0.4}
                jnp.discoveryPort=1102
                jnp.discoveryTTL=16
                jnp.discoveryTimeout=5000
                jnp.maxRetries=1
           ]]>
           </attribute>
        </delegate-config>
        <!-- NOTE: YOU MUST ADD THIS ELEMENT, BUT THE VALUE DOESN'T MATTER
             BE SURE THE CORRECT VALUE IS IN java.naming.provider.url ABOVE -->
        <binding port="1200"/> <!-- Can also be 1300, 1400, 1500 -->
      </service-config>
 
      <!-- **************** http-invoker.sar & httpha-invoker.sar*************** -->
      <!-- EJBInvoker -->
      <service-config name="jboss:service=invoker,type=http"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config>
            <attribute name="InvokerURLSuffix">:${port}/invoker/EJBInvokerServlet</attribute>
        </delegate-config>
         <!-- 
            MUST BE THE SAME AS
            TOMCAT HTTP CONNECTOR BELOW !!!
             -->
         <binding port="8180"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
        <!-- JMXInvoker -->
      <service-config name="jboss:service=invoker,type=http,target=Naming"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config>
            <attribute name="InvokerURLSuffix">:${port}/invoker/JMXInvokerServlet</attribute>
        </delegate-config>
         <!-- 
            MUST BE THE SAME AS
            TOMCAT HTTP CONNECTOR BELOW !!!
             -->
         <binding port="8180"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
        <!-- readonly JMXInvoker -->
      <service-config name="jboss:service=invoker,type=http,target=Naming,readonly=true"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config>
            <attribute name="InvokerURLSuffix">:${port}/invoker/readonly/JMXInvokerServlet</attribute>
        </delegate-config>
         <!-- 
            MUST BE THE SAME AS
            TOMCAT HTTP CONNECTOR BELOW !!!
             -->
         <binding port="8180"/> <!-- Can be also 8280, 8380, 8480 -->
      </service-config>
 
    <!-- **************** httpha-invoker.sar*************** -->
      <!-- EJBInvokerHA -->
      <service-config name="jboss:service=invoker,type=httpHA"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config>
            <attribute name="InvokerURLSuffix">:${port}/invoker/EJBInvokerHAServlet</attribute>
        </delegate-config>
         <binding port="8180"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
      <!-- JMXInvokerHA -->
      <service-config name="jboss:service=invoker,type=http,target=HAJNDI"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
         <delegate-config>
            <attribute name="InvokerURLSuffix">:${port}/invoker/JMXInvokerHAServlet</attribute>
        </delegate-config>
         <binding port="8180"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
      <!-- ********************* jboss-ws4ee.sar **************** -->
 
      <!-- Web Service related services -->
      <service-config name="jboss.ws4ee:service=AxisService"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
         >
        <delegate-config portName="WebServicePort" hostName="WebServiceHost"/>
        <binding port="8180" host="${jboss.bind.address}"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
      <!-- ********************* hsqldb-ds.xml ********************** -->
 
      <!-- Hypersonic related services 
 
            Only if using TCP setup (local file setup by default)
 
      <service-config name="jboss.jca:service=ManagedConnectionFactory,name=DefaultDS"
         delegateClass="org.jboss.services.binding.XSLTConfigDelegate"
      >
         <delegate-config>
         <xslt-config configName="ManagedConnectionFactoryProperties"><![CDATA[
<xsl:stylesheet
      xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
 
  <xsl:output method="xml" />
  <xsl:param name="host"/>
  <xsl:param name="port"/>
 
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
 
  <xsl:template match="config-property[@name='ConnectionURL']">
    <config-property type="java.lang.String" name="ConnectionURL">jdbc:hsqldb:hsql://<xsl:value-of select='$host'/>:<xsl:value-of select='$port'/></config-property>
  </xsl:template>
 
  <xsl:template match="*|@*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
]]>
         </xslt-config>
         </delegate-config>
         <binding host="localhost" port="1801" /> <!-- Can also be 1901, 2001, 2101 -->
      </service-config>
 
      <service-config name="jboss:service=Hypersonic"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
      >
         <delegate-config portName="Port" />
         <binding port="1801" /> <!-- Can also be 1901, 2001, 2101 -->
      </service-config>
 
      -->
 
      <!-- ********************* tomcat ********************** -->
 
      <service-config name="jboss.web:service=WebServer"
         delegateClass="org.jboss.services.binding.XSLTFileDelegate"
         >
         <delegate-config>
            <xslt-config configName="ConfigFile"><![CDATA[
   <xsl:stylesheet
         xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
 
     <xsl:output method="xml" />
     <xsl:param name="port"/>
 
     <xsl:variable name="portAJP" select="$port - 71"/>
     <xsl:variable name="portHttps" select="$port + 363"/>
 
     <xsl:template match="/">
       <xsl:apply-templates/>
     </xsl:template>
 
      <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:template match="*|@*">
       <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
     </xsl:template>
   </xsl:stylesheet>
   ]]>
            </xslt-config>
         </delegate-config>
         <binding port="8180"/> <!-- Can also be 8280, 8380, 8480 -->
      </service-config>
 
      <!-- ********************* jboss messaging ********************** -->
 
      <service-config name="jboss.messaging:service=Connector,transport=socket" 
                      delegateClass="org.jboss.services.binding.AttributeMappingDelegate"> 
         <delegate-config> 
            <attribute name="InvokerLocator">socket://${jboss.bind.address}:4557/?dataType=jms&amp;serializationtype=jms&amp;timeout=0&amp;leasePeriod=20000&amp;socket.check_connection=false&amp;marshaller=org.jboss.jms.server.remoting.JMSWireFormat&amp;unmarshaller=org.jboss.jms.server.remoting.JMSWireFormat</attribute> 
         </delegate-config> 
         <binding port="4557"/> <!-- Can also be 4657, 4757, 4857 -->
      </service-config>
 
   </server>
</service-bindings>

The ports can be incremented by 100 for each port in a new port setting, so for instance 8180 can be changed to 8280 to give you a new range. Just leave alone the section headed with:

You should be able to see the differences in the example bindings file between ports-01 and ports-02 setups and I’ve also commented each port change with so you can see which ports to change.

With that file done, next go to your JBoss install directory and then look for your server, if you’re using the default then it will be called… default. You can now duplicate this server if you need to and you’ll be able to run both at the same time with this tutorial. In here we look in the conf directory for a file called jboss-service.xml. The path to this looks something like this: \jboss\server\[SERVER NAME]\conf\jboss-service.xml

So open this file up and look in here for the following section:

   <mbean code="org.jboss.services.binding.ServiceBindingManager"
     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName">[SERVER NAME]</attribute>
     <attribute name="StoreURL">${jboss.home.url}/binding/binding.xml</attribute>
     <attribute name="StoreFactoryClassName">
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>

We then un-comment this section, e.g. remove the ‘–>’. Then we alter the ServerName attribute to match your server’s name and the StoreURL attribute to point to your new bindings file. Repeat this step for each of your servers. The servers name you enter is used to look up the ports configuration in the binding.xml, so if you left it as the default ports-01 then this will be the server name you need to enter.

And that’s pretty much it, if you have port conflict errors onyour startup then look in these files and also check that your application is set to use the particular ports, for instance using ATG we set the dynamo server to use RMI port xxxxx etc… which maps into your JBoss ports config. One other thing – you will always be able to see the ports being used in your JBoss logs if you need to debug.

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

Technorati Tags: , , , , ,

  1. Adding and changing Mod JK JVM route, URI encoding and thread settings for JBoss
  2. Setting the JDK version and compiler in JBoss for JSP pages
  3. Creating XML from PHP/ MySQL for use with SPRY
  4. Google Maps API part 1: Accurate Geocoding for UK Postcodes
  5. Using Javascript/ AJAX to post HTML form data
  6. Setting Database Connections in JBoss/ ATG
  7. How to Setup Debugging in Eclipse for JBoss
  8. Hot Deploy Java code/ ATG components on JBoss
  9. Changing the HTTP port Oracle uses

Delicious Digg Facebook LinkedIn reddit StumbleUpon Twitter Email Print Friendly

About larry

My journey of wonderment and the things that I discovery along the way.