Skip to content
Michal Karm Babacek edited this page Jul 18, 2014 · 4 revisions

Blog-like list of noteworthy articles | mod_cluster user forum

Q: I started mod_cluster and it looks like it's using only one of the workers

Karm: A: One must give the system some time, in matter of the amount of new sessions created, to settle and pick other nodes. An example from an actual environment: You have 3 nodes with the following Load values:

Node jboss-6,   Load: 20
Node jboss-6-2, Load: 90
Node jboss-6-3, Load:  1

Yes, this means that jboss-6-2 is almost not loaded at all whereas jboss-6-3 is desperately overloaded. Now, I send 1001 requests, each representing a new session (the client is forgetting cookies). The distribution of the requests will be as follows:

Node jboss-6   served 181 requests
Node jboss-6-2 served 811 requests
Node jboss-6-3 served   9 requests

So, generally, yes, the least loaded box received by far the greatest amount of requests, but it did not receive them all. Furthermore, and this concerns your case, for some time from the start, it was jboss-6 who was getting requests.

This whole magic is in place in order to prevent congestion.


Q: JBoss AS instances in Domain mode with mod_cluster load balancer

Karm: A: Here you go:

Goal: To have Domain Controller and one Host Controller with one server running on a one box and a second Host Controller with second server running on the second box. Both servers should automatically register to the mod_cluster load balancer running on the third box.

This example is valid for JBoss AS 7.x, JBoss EAP 6.x and Apache HTTP Server 2.2.x. It will work for Wildfly application server as well. If you would like to use Apache HTTP Server 2.4.x, mind the slight configuration changes regarding Allow from... vs. Requires granted.

Requirements: 3 virtual machines or physical servers, JBoss AS, Apache HTTP Server and mod_cluster distributions.

First, we are about to install the Apache HTTP Server to act as mod_cluster load balancer. Please, note the paths, IP addresses and ports are arbitrary unless stated otherwise.

Apache HTTP Server
Installed in : /opt/load-balancer/jboss-ews-2.x/httpd
box IP:        192.168.122.74
  1. run .postinstall

  2. make sure you have these modules in the appropriate modules/ directory:

    • mod_slotmem.so
    • mod_proxy_cluster.so
    • mod_manager.so
    • mod_advertise.so
  3. comment out mod_proxy_balancer.so (it's incompatible with our mod_proxy_cluster.so)

  4. for the sake of this example, comment out any Listen directives in httpd.conf

  5. LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

  6. /opt/load-balancer/jboss-ews-2.x/httpd/conf.d/mod_cluster.conf

    LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
    LoadModule slotmem_module modules/mod_slotmem.so
    
    LoadModule manager_module modules/mod_manager.so
    LoadModule advertise_module modules/mod_advertise.so
    
    Listen 192.168.122.74:2181
    
    MemManagerFile "/opt/load-balancer/jboss-ews-2.x/httpd/cache/mod_cluster"
    
    ServerName 192.168.122.74:2181
    
    <IfModule manager_module>
        Listen 192.168.122.74:8847
        LogLevel debug
        <VirtualHost 192.168.122.74:8847>
            ServerName 192.168.122.74:8847
            <Directory />
                Order deny,allow
                Deny from all
                Allow from all
            </Directory>
            AdvertiseGroup 224.0.1.111:23365
            EnableMCPMReceive
            <Location /mcm>
                SetHandler mod_cluster-manager
                Order deny,allow
                Deny from all
                Allow from all
            </Location>
        </VirtualHost>
    </IfModule>
    
JBoss AS
Unzipped into: /opt/jboss-eap-6.x
  1. use /opt/jboss-eap-6.x/bin/add-user.sh to add these 3 users to ManagementRealm
    • admin
    • machine1
    • machine2 Please, note that machine1 and machine2 user names are not arbitrary. Answer yes to all the questions and use the same passwords (this is just for testing): R3dHatRulezz. or update the <secret value=" attributes accordingly.
  2. copy domain directory so as to create the following structure: /opt/jboss-eap-6.x/ ├── domain ├── machine1 │ └── domain └── machine2 └── domain
Domain Controller

Edit machine1/domain/configuration/domain.xml, so as:

+++
<cluster-password>${jboss.messaging.cluster.password:jboss}</cluster-password>
+++
<socket-binding-group name="full-ha-sockets" default-interface="public">
    +++
    <socket-binding name="modcluster" port="0" multicast-address="224.0.1.111" multicast-port="23365"/>
    +++
</socket-binding-group>
+++
<server-groups>
    <server-group name="main-server-group" profile="full-ha">
        <jvm name="default">
            <heap size="713m" max-size="713m"/>
            <permgen max-size="128m"/>
        </jvm>
        <socket-binding-group ref="full-ha-sockets"/>
    </server-group>
</server-groups>
+++

Configure the master in machine1/domain/configuration/host-master.xml:

+++
<host name="machine1-master" xmlns="urn:jboss:domain:...
+++
        <security-realm name="ManagementRealm">
            <server-identities>
                 <secret value="UjNkSGF0UnVsZXp6Lg=="/>
            </server-identities>
+++
Host Controller 1

Configure your Host Controller 1 in machine1/domain/configuration/host-slave.xml. Please, note the name is not arbitrary, it must match the user names created above.

<host name="machine1" xmlns="urn:jboss:domain:...
+++
        <security-realm name="ManagementRealm">
            <server-identities>
                 <secret value="UjNkSGF0UnVsZXp6Lg=="/>
            </server-identities>
+++
<servers>
    <server name="server-one" group="main-server-group"/>
</servers>
+++
Host Controller 2

Configure your Host Controller 2 machine2/domain/configuration/host-slave.xml:

+++
<host name="machine2" xmlns="urn:jboss:domain:...
+++
        <security-realm name="ManagementRealm">
            <server-identities>
                 <secret value="UjNkSGF0UnVsZXp6Lg=="/>
            </server-identities>
+++
<servers>
    <server name="server-two" group="main-server-group">
        <socket-bindings port-offset="150"/>
    </server>
</servers>
+++
Overview of the current layout

mod_cluster example

Run!

For the sake of this example, let's suppose you have the Apache HTTP Server residing on the box 192.168.122.74. Copy your /opt/jboss-eap-6.x folder to the two boxes that are supposed to act as JBoss AS worker nodes, e.g. 192.168.122.78 and 192.168.122.204.

  1. Make sure your firewalls allow UDP multicast between the nodes and that all the used ports are open
  2. Please, check firewalls and network interfaces again, i.e. Apache HTTP Server must be able to access AJP connector on your JBoss AS workers etc.
  3. Start Apache HTTP Server on 192.168.122.74
  • ./apachectl start``` in ```/opt/load-balancer/jboss-ews-2.x/httpd/sbin
  • one might appreciate seeing the mod_cluster messages: tail -f /opt/load-balancer/jboss-ews-2.x/httpd/logs/error_log
  1. Start Domain Controller on 192.168.122.78, /opt/jboss-eap-6.x/bin
  • ./domain.sh --host-config=host-master.xml -Djboss.domain.base.dir=/opt/jboss-eap-6.x/machine1/domain -Djboss.bind.address.management=192.168.122.78
  1. Start Host Controller 1 on 192.168.122.78
  • ./domain.sh -Djboss.domain.base.dir=/opt/jboss-eap-6.x/machine1/domain --host-config=host-slave.xml -Djboss.domain.master.address=192.168.122.78 -Djboss.management.native.port=29999 -Djboss.bind.address.management=192.168.122.78 -Djboss.bind.address=192.168.122.78 -Djboss.bind.address.unsecure=192.168.122.78
  1. Start Host Controller 2 on 192.168.122.204
  • ./domain.sh -Djboss.domain.base.dir=/opt/jboss-eap-6.x/machine2/domain --host-config=host-slave.xml -Djboss.domain.master.address=192.168.122.78 -Djboss.bind.address.management=192.168.122.204 -Djboss.bind.address=192.168.122.204 -Djboss.bind.address.unsecure=192.168.122.204
  1. Access http://192.168.122.74:8847/mcm and wait dozen of seconds for two worker nodes to appear
  2. Deploy/manage/play with Domain Controller http://192.168.122.78:9990/

Q: How do I force mod_cluster to use HTTPS instead of AJP?

Karm: A: mod_cluster.conf & standalone-ha.xml