Menu

Official website

Running several JBoss AS on the same server


07 Aug 2007

min read

This article shows you how to run multiple JBoss Application servers on the same machine. This might be really useful if you wish to execute two different versions of the JBoss Application Server, or if you want to experiment with clustering. The main problem when running two or more instances of the JBoss Application server comes from the fact that the servers are using the same ports. Two solutions are presented: binding the JBoss Application Server to an interface and using the binding service manager.

Binding the JBoss Application Server to an interface

The easiest solution is to bind your application server to an interface. This easily done by starting your JBoss instance with the -b option.

For example:

# sh bin/run.sh -b 192.168.17.6
# sh bin/run.sh -b 192.168.17.7

However, this method requires multiple interfaces on the server, which might not always be the case. The other solution is to use the binding service manager for port/host mapping that JBoss provides.

Using the binding service manager

To deploy another instance of JBoss you need to change the ports that JBoss listens to. Here is a table of the ports you need to change:

Service Default port New Port Description

jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3

3873

3973

EJB3

jboss:service=Naming

1098

1198

JNDI

jboss:service=WebService

8083

8183

web service

jboss:service=invoker,type=jrmp

4444

4544

 

jboss:service=invoker,type=pooled

4445

4545

 

jboss:service=HAJNDI

1100,1101

1200,1201

HA JNDI / clusters

jboss:service=invoker,type=pooledha

4448

4548

clusters

jboss:service=CorbaORB

19001

19101

Corba

jboss.jmx:name=SnmpAgent,service=trapd,type=logger

1162

1262

SNMP

jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor

1161

1261

SNMP

jboss.mq:service=InvocationLayer,type=UIL2

8093

8193

JMS

jboss.mq:service=InvocationLayer,type=HTTP

8080

8180

JMS HTTP

jboss.mq:service=JMSProviderLoader,name=HAJNDIJMSProvider

1100

1200

HA JMS

jboss.web:service=WebServer

8080,8443

8180, 8543

Http web server

jboss.messaging:service=Connector,transport=bisocket

4457

4557

JBoss Messaging

Of course, you probably do not have all of these services deployed on your Application Server.

The problem is that these ports are all defined in different files. Happily, the binding service manager lets you redefine these ports in one place.

The JBoss wiki explains it all. Here is a more detailed version on how to proceed.

Basically you can use the binding service manager. In order to do that, edit the file {jbossinstallationdirectory}/server/{instance}/conf/jboss-service.xml and find the ServiceBindingManager MBean.

The jboss-service.xml part we are interested by should look like this:

<!-- ==================================================================== -->
   <!-- Service Binding                                                      -->
   <!-- ==================================================================== -->

   <!--
      | Binding service manager for port/host mapping. This is a sample
      | config that demonstrates a JBoss instances with a server name 'ports-01'
      | loading its bindings from an XML file using the ServicesStoreFactory
      | implementation returned by the XMLServicesStoreFactory.
      |
      | ServerName: The unique name assigned to a JBoss server instance for
      | lookup purposes. This allows a single ServicesStore to handle mulitiple
      | JBoss servers.
      |
      | StoreURL: The URL string passed to org.jboss.services.binding.ServicesStore
      | during initialization that specifies how to connect to the bindings store.
      | StoreFactory: The org.jboss.services.binding.ServicesStoreFactory interface
      | implementation to create to obtain the ServicesStore instance. -->

   <mbean code="org.jboss.services.binding.ServiceBindingManager"

     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName">ports-01</attribute>
     <attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
     <attribute name="StoreFactoryClassName">



       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>

This refers to /docs/examples/binding-manager/sample-bindings.xml as an example. The example contains 4 different ports settings besides the default settings.

You can of course use your own configuration file.

Let’s create our own configuration file that we will call {jbossinstallationdirectory}/server/{instance}/conf/jboss-bindings.xml:

<service-bindings>
   <!-- ********************************************************** -->
   <!-- *                          ports-01                      * -->
   <!-- ********************************************************** -->

   <server name="ports-01">

      <!-- 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>

      <!-- ********************* 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>
         </delegate-config>
         <binding port="1199" host="${jboss.bind.address}"/>

      </service-config>


      <service-config name="jboss:service=WebService"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="Port"/>

         <binding port="8183"/>
      </service-config>


      <service-config name="jboss:service=invoker,type=jrmp"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">

         <delegate-config portName="RMIObjectPort"/>
         <binding port="4544"/>
      </service-config>

      <service-config name="jboss:service=invoker,type=pooled"

         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="ServerBindPort"/>
         <binding port="4545"/>
      </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>
         </delegate-config>
         <binding port="1200" host="${jboss.bind.address}"/>

      </service-config>

      <service-config name="jboss:service=invoker,type=jrmpha"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="RMIObjectPort"/>

         <binding port="4544"/>
      </service-config>

      <service-config name="jboss:service=invoker,type=pooledha"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">

         <delegate-config portName="ServerBindPort"/>
         <binding port="4548"/>
      </service-config>

      <!-- ********************* iiop-service.xml ****************** -->

      <service-config name="jboss:service=CorbaORB"
         delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config portName="Port"/>
         <binding port="3628"/>

      </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"/>
      </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"/>
      </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"/>

      </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"/>
      </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"/>

      </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
                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"/>
      </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"/>
      </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"/>
      </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"/>
      </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"/>
      </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"/>

      </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}"/>
      </service-config>

      <!-- ********************* remoting **************** -->

       <!-- *** remoting connector *** -->
       <service-config name="jboss.remoting:service=Connector,transport=socket"
          delegateClass="org.jboss.services.binding.XSLTConfigDelegate">
          <delegate-config>

             <xslt-config configName="Configuration"><![CDATA[
               <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

                  <xsl:output method="xml" />

                  <xsl:param name="port"/>

                  <xsl:template match="/">
                     <xsl:apply-templates/>

                  </xsl:template>

                  <xsl:template match="attribute[@name='serverBindPort']">
                     <attribute type="java.lang.String" name="serverBindPort"><xsl:value-of select='$port'/></attribute>

                  </xsl:template>

                  <xsl:template match="*|@*">
                     <xsl:copy>
                        <xsl:apply-templates select="@*|node()"/>

                     </xsl:copy>
                  </xsl:template>
               </xsl:stylesheet>
          ]]>
          </xslt-config>

          </delegate-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>

   <!-- ********************* jboss messaging ********************** -->

      <service-config name="jboss.messaging:service=Connector,transport=bisocket"
                      delegateClass="org.jboss.services.binding.AttributeMappingDelegate">
         <delegate-config>

            <attribute name="Configuration"><![CDATA[
               <config>
                  <invoker transport="bisocket">
                     <attribute name="marshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>

                     <attribute name="unmarshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>
                     <attribute name="dataType" isParam="true">jms</attribute>

                     <attribute name="socket.check_connection" isParam="true">false</attribute>
                     <attribute name="timeout" isParam="true">0</attribute>

                     <attribute name="serverBindAddress">${jboss.bind.address}</attribute>
                     <attribute name="serverBindPort">4557</attribute>
                     <attribute name="leasePeriod">10000</attribute>

                     <attribute name="clientSocketClass" isParam="true">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>
                     <attribute name="serverSocketClass">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>
                     <attribute name="numberOfRetries" isParam="true">1</attribute>

                     <attribute name="numberOfCallRetries" isParam="true">1</attribute>
                     <attribute name="clientMaxPoolSize" isParam="true">50</attribute>

                  </invoker>
                 <handlers>
                    <handler subsystem="JMS">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>
                 </handlers>
              </config>

         ]]></attribute>
         </delegate-config>
         <binding port="4557"/>
      </service-config>

   </server>

Don’t forget to change

<attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>

to

<attribute name="StoreURL">${jboss.server.config}/jboss-bindings.xml</attribute>

You are now ready to start your second instance of JBoss AS.

Nicolas Leroux is a senior software developer at Lunatech Research. Although comments are disabled on this blog, he encourages you to send him comments by mail, corrections as well as opinions. Feedback is valued._

expand_less