10

To replace a legacy service I am interested in having two different webapps on two different HTTP port numbers, e.g., 8080 -> webapp1 (browser service), 8200 -> webapp2 (REST, new version uses RESTEasy). Each will be the "root context" on that port number.

The "standard" answer on this site relates to JBoss 5, which is two major versions back in history and has a zillion configuration format changes.

I'm using JBoss AS 7.0.2.Final and the "standalone" deployment. Anybody done this and can share the configuration used? Thanks.

idarwin
  • 607
  • 4
  • 19
  • What I didn't make clear is that I want to run two different ports in the same instance so they can share the connection pool. I believe the first two answers do not meet this need, as it seems that the Managed Domain uses a separate JVM for each server and the two standalone server solution obviously does so too. I can't believe this is hard in JBoss, as it's trivial in Apache Httpd and Tomcat, among others. – idarwin Apr 23 '12 at 14:42

3 Answers3

7

Managed Domain

You might consider running a Managed Domain instance. This would allow you to maintain two server instances with a web application each, as well as the ease of maintaining the port and interface declarations from a single console view.

To aim would be one Managed Domain with two servers. Each server would belong to a different server group. Each server group would have it's own interface or port declarations as you require.

This gives you a single management console, with a set of relative server groups to assign your current and future servers to, with the ability to change, reassign or disable on the fly.

Configuration

The files you need to be aware of are both the host.xml and domain.xml configuration files under the following file path.

~/JBOSS_HOME/domain/configuration

From the domain.xml we can see the socket binding groups. The following example is a default "standard-sockets" group, but you are free to create as many groups as you want, with as many or as little declarations as you need.

 <socket-binding-groups>
        <socket-binding-group name="standard-sockets" default-interface="public">
            <socket-binding name="ajp" port="8009"/>
            <socket-binding name="http" port="8080"/>
            <socket-binding name="https" port="8443"/>
            <socket-binding name="osgi-http" interface="management" port="8090"/>
            <socket-binding name="remoting" port="4447"/>
            <socket-binding name="txn-recovery-environment" port="4712"/>
            <socket-binding name="txn-status-manager" port="4713"/>
            <outbound-socket-binding name="mail-smtp">
                <remote-destination host="localhost" port="25"/>
            </outbound-socket-binding>
        </socket-binding-group>
 ...

You could create two socket binding groups for your needs, catering to the two sets of ports you might need. Once they exist, you want a server group to know about them. Lets look further down the domain.xml file.

We can see in the following example that a server group references a socket binding group. For bonus points, we can see that some applications are deployed to them. This has occurred via the Management Console, but AS 7 persists the console and CLI changes to the configuration.

   <server-groups>
    <server-group name="main-server-group" profile="full">
        <jvm name="default">
            <heap size="1303m" max-size="1303m"/>
            <permgen max-size="256m"/>
        </jvm>
        <socket-binding-group ref="full-sockets"/>
        <deployments>
            <deployment name="your_application.jar" runtime-name="your_application.jar"/>
            <deployment name="your_application_02.ear" runtime-name="your_application_02.ear"/>
            <deployment name="test.war" runtime-name="test.war"/>
        </deployments>
    </server-group>
    <server-group name="other-server-group" profile="full-ha">
        <jvm name="default">
            <heap size="1303m" max-size="1303m"/>
            <permgen max-size="256m"/>
        </jvm>
        <socket-binding-group ref="full-ha-sockets"/>
        <deployments>
            <deployment name="your_application_02.ear" runtime-name="your_application_02.ear"/>
            <deployment name="test.war" runtime-name="test.war"/>
        </deployments>
    </server-group>
</server-groups>

The domain.xml file is the configuration of the domain controller, which is the "boss" of the managed domain. The actual server information is contained in the host controller, so let's look at the host.xml file.

<servers>
    <server name="server-one" group="main-server-group">
    </server>
    <server name="server-two" group="main-server-group" auto-start="true">
        <!-- server-two avoids port conflicts by incrementing the ports in
             the default socket-group declared in the server-group -->
        <socket-bindings port-offset="150"/>
    </server>
    <server name="server-three" group="other-server-group" auto-start="false">
        <!-- server-three avoids port conflicts by incrementing the ports in
             the default socket-group declared in the server-group -->
        <socket-bindings port-offset="250"/>
    </server>
</servers>

We can see three servers in the default domain. The third is a member of the other-server-group group, while the first two are members of the main-server-group group. Notice the port binding declarations also.

You could delete the third server, and dedicate server one and server two to your first and second web applications respectively. Each server can belong to a unique group. Each group can declare a unique port. After this, you're ready to deploy your applications to their respective groups and you're away.

Using Management Tools

The examples are showing XML, but you should use the Management Console or the Management CLI when configuring your installation. The console is simple enough, so here's some CLI operations to help.

To show the server groups:

[domain@localhost:9999 /] /server-group=*:read-resource(include-runtime=true)

To show the socket binding groups:

[domain@localhost:9999 /] /socket-binding-group=*:read-resource(include-runtime=true)

You want to expose the specific http attribute values, so we can amend our CLI operation to run on that child node. Including the runtime parameter helps us catch anything passed at runtime that hasn't been written to or persisted to the server model.

[domain@localhost:9999 /] /socket-binding-group=standard-sockets/socket-binding=http:read-resource(include-runtime=true)

And here's how you write to it.

[domain@localhost:9999 /] /socket-binding-group=standard-sockets/socket-binding=http:write-attribute(name=port,value=8081)

That should get you started. As you might gather, I'm a fan of the Managed Domain...

davidryan
  • 2,222
  • 20
  • 31
  • Hi I followed all the steps to deploy two app on different ports, What I did is defined 1 app in main-server-group using ha-sockets and 1 app in other-server-group using full-sockets and did required changes in host.xml also but still the app is deployed to default port which is defined as 8090 according to standalone.xml. Is there any more steps to deploy app on different ports? – Pulkit May 19 '14 at 17:47
  • Thank you very much for this write up. Although an old answer the "Managed Domain instance" hint got me on the right track to support multiple roots on different ports :) – Sverrir Sigmundarson Mar 26 '19 at 15:27
3

Create two separate standalone configurations, then point to the correct configuration file at startup with the -c parameter.

For example, say you copied the default standalone.xml file as a starting point for the first instance to a file called standalone-server1.xml. You'd then start that instance with the following command:

$jboss_home/bin/standalone.sh -c standalone-server1.xml

Make sure you edit the socket-binding-group settings as needed to avoid port conflicts. Consider using the port-offset property to have JBoss automagically bump your port numbers for you.

GDP
  • 8,109
  • 6
  • 45
  • 82
juettner
  • 64
  • 5
  • But chad how can you make your application deployed to particular port, it will deployed to port defined in (http). Is there any way that we can force our application to be deployed on any particular port of the two instances launched using tow different configuration file? – Pulkit May 19 '14 at 21:22
1

Thanks @ddri,As per steps mentioned by @ddri I want to add few things, I followed all the steps mentioned by you @ddri but my apps were not deployed on particular ports, I want to make a correction(which worked in my case)

Step 1 Open domain.xml and choose any socket binding group that you are going to use, by default we have

1) standard-sockets
2) ha-sockets
3) full-sockets
4) full-ha-sockets

I used 2,3. Here is my snippet

<socket-binding-group name="ha-sockets" default-interface="public">
            <socket-binding name="ajp" port="8009"/>
            <socket-binding name="http" port="8888"/>
            <socket-binding name="https" port="8443"/>
            <socket-binding name="jgroups-diagnostics" port="0" multicast-address="224.0.75.75" multicast-port="7500"/>
            <socket-binding name="jgroups-mping" port="0" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45700"/>
            <socket-binding name="jgroups-tcp" port="7600"/>
            <socket-binding name="jgroups-tcp-fd" port="57600"/>
            <socket-binding name="jgroups-udp" port="55200" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45688"/>
            <socket-binding name="jgroups-udp-fd" port="54200"/>
            <socket-binding name="modcluster" port="0" multicast-address="224.0.1.105" multicast-port="23364"/>
            <socket-binding name="osgi-http" interface="management" port="8090"/>
            <socket-binding name="remoting" port="4447"/>
            <socket-binding name="txn-recovery-environment" port="4712"/>
            <socket-binding name="txn-status-manager" port="4713"/>
            <outbound-socket-binding name="mail-smtp">
                <remote-destination host="localhost" port="25"/>
            </outbound-socket-binding>

Step 2 In domain.xml find <server-groups> ad configure your <socket-binding-group> for each of them, here is my snippet

<server-groups>
        <server-group name="1st-server-group" profile="ha">
            <jvm name="default">
                <heap size="64m" max-size="512m"/>
            </jvm>
            <socket-binding-group ref="ha-sockets"/>
        </server-group>
        <server-group name="2nd-server-group" profile="full-ha">
            <jvm name="default">
                <heap size="64m" max-size="512m"/>
            </jvm>
            <socket-binding-group ref="full-ha-sockets"/>
        </server-group>

Step 3 Open host.xml and confiure your server with server-group

<servers>
        <server name="server-one" group="1st-server-group">

        </server>
        <server name="server-two" group="2nd-server-group">

        </server>

Step 4 Go to your {JBoss_Home}/bin folder and run domain.bat file and make sure there is not exception coming for port already binded.

=============================================================================== Step 5 Open jboss-cli from {JBoss_Home}/bin and type

connect

and confirm that you are running jboss under domain configuration not standalone configuration

[domain@localhost:9999 /]

To deploy any app type

deploy FacebookTool.war --server-groups=1st-server-group

and make sure whatever app you are running should have a </distributable> tag in their web.xml.

Now you can run two app on different ports of single instance of jboss :)

Pulkit
  • 3,953
  • 6
  • 31
  • 55