3.2.8. Clustering Changes

3.2.8.1. Make Changes to Your Application for Clustering

  1. Start JBoss EAP 6 with clustering enabled

    To enable clustering in JBoss EAP 5.x, you needed to start your server instances using the all profile or some derivation of it, like this:
    $ EAP5_HOME/bin/run.sh -c all
    In JBoss EAP 6, the method for enabling clustering depends on whether the servers are standalone or running in a managed domain.
    1. Enable clustering for servers running in a managed domain

      To enable clustering for servers started using the domain controller, update your domain.xml and designate a server group to use the ha profile and ha-sockets socket binding group. For example:
      <server-groups>
        <server-group name="main-server-group" profile="ha">
          <jvm name="default">
            <heap size="64m" max-size="512m"/>
          </jvm>
          <socket-binding-group ref="ha-sockets"/>
        </server-group>
      </server-group>
    2. Enable clustering for standalone servers

      To enable clustering for standalone servers, start the server using the appropriate configuration file as follows:
      $ EAP_HOME/bin/standalone.sh --server-config=standalone-ha.xml -Djboss.node.name=UNIQUE_NODE_NAME
  2. Specify the bind address

    In JBoss EAP 5.x, you would typically indicate the bind address used for clustering using the -b command line argument like this:
    $ EAP5_HOME/bin/run.sh -c all -b 192.168.0.2
    JBoss EAP 6 binds sockets to the IP addresses and interfaces contained in the <interfaces> elements in standalone.xml, domain.xml and host.xml files. The standard configurations that ship with JBoss EAP include two interface configurations:
    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
        </interface>
        <interface name="public">
           <inet-address value="${jboss.bind.address:127.0.0.1}"/>
        </interface>
    </interfaces>
    These interface configurations use the values of the system properties jboss.bind.address.management and jboss.bind.address. If these system properties are not set, the default 127.0.0.1 is used for each value.
    You can also specify the bind address as a command line argument when you start the server or you can explicitly define it within the JBoss EAP 6 server configuration file.
    • Specify the bind argument on the command line when you start the JBoss EAP standalone server.
      The following is an example of how to specify the bind address on the command line for a standalone server:
      EAP_HOME/bin/standalone.sh -Djboss.bind.address=127.0.0.1

      Note

      You can also use the -b argument, which is a shortcut for -Djboss.bind.address=127.0.0.1:
      EAP_HOME/bin/standalone.sh -b=127.0.0.1
      The JBoss EAP 5 syntax format is also still supported:
      EAP_HOME/bin/standalone.sh -b 127.0.0.1
      Note that the -b argument only changes the public interface. It does not affect the management interface.
    • Specify the bind address in the server configuration file.
      For servers running in a managed domain, specify the bind addresses in the domain/configuration/host.xml file. For standalone servers, specify the bind addresses in the standalone-ha.xml file.
      In the following example, the public interface is specified as the default interface for all sockets within the ha-sockets socket binding group.
      <interfaces>
        <interface name="management">
          <inet-address value="192.168.0.2"/>
        </interface>
        <interface name="public">
          <inet-address value="192.168.0.2"/>
        </interface>
      </interfaces>
      <socket-binding-groups>
        <socket-binding-group name="ha-sockets" default-interface="public">
          <!-- ... -->
        </socket-binding-group>
      </socket-binding-groups>

      Note

      If you specify the bind address as a hard-coded value rather than a system property in the configuration file, you can not override it with a command line argument.
  3. Configure jvmRoute to support mod_jk and mod_proxy

    In JBoss EAP 5, the web server jvmRoute was configured using a property in the server.xml file. In JBoss EAP 6, the jvmRoute attribute is configured in the web subsystem of the server configuration file using the instance-id attribute as follows:
    <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false" instance-id="{JVM_ROUTE_SERVER}">
    
    The {JVM_ROUTE_SERVER} above should be replaced by the jvmRoute server ID.
    The instance-id can also be set using the Management Console.
  4. Specify the multicast address and port

    In JBoss EAP 5.x, you could specify the multicast address and port used for intra-cluster communication using the command line arguments -u and -m, respectively, like this:
    $ EAP5_HOME/bin/run.sh -c all -u 228.11.11.11 -m 45688
    In JBoss EAP 6, the multicast address and port used for intra-cluster communication are defined by the socket-binding referenced by the relevant JGroups protocol stack as follows:
    <subsystem xmlns="urn:jboss:domain:jgroups:1.0" default-stack="udp">
        <stack name="udp">
            <transport type="UDP" socket-binding="jgroups-udp"/>
            <!-- ... -->
        </stack>
    </subsystem>
    <socket-binding-groups>
        <socket-binding-group name="ha-sockets" default-interface="public">
            <!-- ... -->
            <socket-binding name="jgroups-udp" port="55200" multicast-address="228.11.11.11" multicast-port="45688"/>
            <!-- ... -->
        </socket-binding-group>
    </socket-binding-groups>
    
    If you prefer to specify the multicast address and port in the command line, you can define the multicast address and ports as system properties and then use those properties on the command line when you start the server. In the following example, jboss.mcast.addr is the variable name for the multicast address and jboss.mcast.port is the variable name for the port.
    <socket-binding name="jgroups-udp" port="55200"
     multicast-address="${jboss.mcast.addr:230.0.0.4}" multicast-port="${jboss.mcast.port:45688}"/>
    
    You can then start your server using the following command line arguments:
    $ EAP_HOME/bin/domain.sh -Djboss.mcast.addr=228.11.11.11 -Djboss.mcast.port=45688
  5. Use an alternate protocol stack

    In JBoss EAP 5.x, you could manipulate the default protocol stack used for all clustering services using the jboss.default.jgroups.stack system property.
    $ EAP5_HOME/bin/run.sh -c all -Djboss.default.jgroups.stack=tcp
    In JBoss EAP 6, the default protocol stack is defined by the JGroups subsystem within domain.xml or standalone-ha.xml:
    <subsystem xmlns="urn:jboss:domain:jgroups:1.0" default-stack="udp">
        <stack name="udp">
            <!-- ... -->
        </stack>
    </subsystem>
  6. Replace Buddy Replication

    JBoss EAP 5.x used JBoss Cache Buddy Replication to suppress replication of data to all instances in a cluster.
    In JBoss EAP 6, Buddy Replication has been replaced by Infinispan's distributed cache, also known as DIST mode. Distribution is a powerful clustering mode which allows Infinispan to scale linearly as more servers are added to the cluster. The following is an example of how to configure the server to use the DIST caching mode.
    1. Open a command line and start the server with either the HA or Full Profile, for example:
      EAP_HOME/bin/standalone.sh -c standalone-ha.xml
    2. Open another command line and connect to the Management CLI.
      • For Linux, enter the following at the command line:
        $ EAP_HOME/bin/jboss-cli.sh --connect
        
      • For Windows, enter the following at a command line:
        C:\>EAP_HOME\bin\jboss-cli.bat --connect
        
      You should see the following response:
      Connected to standalone controller at localhost:9999
    3. Issue the following commands:
      /subsystem=infinispan/cache-container=web/:write-attribute(name=default-cache,value=dist)
      /subsystem=infinispan/cache-container=web/distributed-cache=dist/:write-attribute(name=owners,value=3)
      :reload
      
      You should see the following response after each command:
      "outcome" => "success"
      
      These commands modify the dist <distributed-cache> element in the web <cache-container> configuration in the infinispan subsystem of the standalone-ha.xml file as follows:
      <cache-container name="web" aliases="standard-session-cache" default-cache="dist" module="org.jboss.as.clustering.web.infinispan">
          <transport lock-timeout="60000"/>
          <replicated-cache name="repl" mode="ASYNC" batching="true">
              <file-store/>
          </replicated-cache>
          <replicated-cache name="sso" mode="SYNC" batching="true"/>
          <distributed-cache name="dist" owners="3" l1-lifespan="0" mode="ASYNC" batching="true">
              <file-store/>
          </distributed-cache>
      </cache-container>
      
      For more information, refer to the chapter entitled Clustering in Web Applications in the Development Guide for JBoss EAP 6 located on the Customer Portal at https://access.redhat.com/site/documentation/JBoss_Enterprise_Application_Platform/.