mod_cluster configuration examples

Solution In Progress - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.4
    • 7.x
  • Red Hat JBoss Core Services (JBCS)
  • Red Hat JBoss Web Server (JWS)
  • Apache httpd
    • 2.2
    • 2.4
  • mod_cluster
    • 1.2.x
    • 1.3.x

Issue

  • mod_cluster configuration examples

Resolution

Simple mod_cluster configuration:

The simplest mod_cluster configuration needs the following configuration in Apache, and the use of an HA profile in JBoss EAP, with server advertise enabled.

Note: Use `Require ip xxx.xxx.xxx.xxx` instead of `Deny/Allow` in Apache 2.4

Apache mod_cluster configuration:

File ${APACHE_DIR}/conf.d/mod_cluster.conf

# mod_proxy_balancer should be disabled when mod_cluster is used
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

MemManagerFile /var/cache/mod_cluster

<IfModule manager_module>

  Listen 6666
  <VirtualHost *:6666>

    RewriteEngine off

      <Directory />
        Order deny,allow
        Deny from all
        Allow from XXX.XXX.XXX.XXX
      </Directory>

    ServerAdvertise on
    AdvertiseFrequency 5
    EnableMCPMReceive On
    CreateBalancers 0
    LogLevel info

    ErrorLog  "/var/logs/httpd/modcluster.log"
    CustomLog "/var/logs/httpd/modcluster.access_log"

    <Location /mod_cluster_manager>
      SetHandler mod_cluster-manager
      Order deny,allow
      Deny from all
      Allow from YYY.YYY.YYY.YYY
   </Location>
  </VirtualHost>

</IfModule>

JBoss EAP configuration for mod_cluster:

Ensure the mod-cluster-config configuration in JBoss EAP has configured advertise-socket="modcluster" and advertise="true"

Mod_cluster configuration with same "context" in different applications

The different applications with the same context needs at least to be deployed in different JBoss EAP instances, with different balancer names. For example,

Apache mod_cluster configuration:

CreateBalancers 1 -> The balances will be no created by Apache, but JBoss EAP.
ServerAdvertise off -> Server Advertise disabled. A list of Apache servers will be configured in JBoss EAP
EnableMCPMReceive On -> Enable the mod_cluster protocol in Apache

Note: Use `Require ip xxx.xxx.xxx.xxx` instead of `Deny/Allow` in Apache 2.4

File ${APACHE_DIR}/conf.d/mod_cluster.conf

# mod_proxy_balancer should be disabled when mod_cluster is used
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

MemManagerFile /var/cache/mod_cluster

<IfModule manager_module>

  Listen 6666
  <VirtualHost *:6666>

    RewriteEngine off

      <Directory />
        Order deny,allow
        Deny from all
        Allow from XXX.XXX.XXX.XXX
      </Directory>

    ServerAdvertise off
    EnableMCPMReceive On
    CreateBalancers 1
    LogLevel info

    ErrorLog  "/var/logs/httpd/modcluster.log"
    CustomLog "/var/logs/httpd/modcluster.access_log"

    <Location /mod_cluster_manager>
      SetHandler mod_cluster-manager
      Order deny,allow
      Deny from all
      Allow from YYY.YYY.YYY.YYY
   </Location>
  </VirtualHost>

</IfModule>

File ${APACHE_DIR}/conf.d/virtualhosts.conf

NameVirtualHost *:80

#Dummy VirtualHost for access diferent to correct URLs, that will return a 404 error.
#The default VirtualHost must be the first one evaluated by Apache.
<VirtualHost *:80>
  ServerName default

  ErrorLog "/var/log/httpd/not_expected_requests.log"
  CustomLog "/var/log/httpd/not_expected_requests.access_log"

  RewriteOptions AllowAnyURI

  RewriteCond %{REQUEST_URI} !^/error/(.*)$
  RewriteRule ^(.*)$ - [L,R=404]

</VirtualHost>

#Access from fqdn_1.example.com
<VirtualHost *:80>
  ServerName fqdn_1.example.com

  ErrorLog  "/var/log/httpd/fqdn_1_example_com.error_log"
  CustomLog "/var/log/httpd/fqdn_1_example_com.access_log"

  ProxyPassMatch ^/error/(.*) !

  ProxyPass        / balancer://balancer_1/ stickysession=JSESSIONID|jsessionid nofailover=On
  ProxyPassReverse / balancer://balancer_1/
</VirtualHost>

#Access from fqdn_2.example.com
<VirtualHost *:80>
  ServerName fqdn_2.example.com

  ErrorLog  "/var/log/httpd/fqdn_2_example_com.error_log"
  CustomLog "/var/log/httpd/fqdn_2_example_com.access_log"

  ProxyPassMatch ^/error/(.*) !

  ProxyPass        / balancer://balancer_2/ stickysession=JSESSIONID|jsessionid nofailover=On
  ProxyPassReverse / balancer://balancer_2/
</VirtualHost>

JBoss EAP configuration for mod_cluster:

Ensure advertise="false" in the JBoss EAP configuration.

EAP 6.4

<mod-cluster-config proxy-list="${apache.proxy.list}" balancer="${modcluster.balancer.name}" advertise="false" connector="ajp">

apache.proxy.list property configuration. Could be different by server-group, server, etc.

<property name="apache.proxy.list" value="xx.xx.xx.xx:6666,yy.yy.yy.yy:6666"/>

EAP 7.x

<mod-cluster-config proxies="proxy1 proxy2" balancer="${modcluster.balancer.name}" advertise="false" connector="ajp">

proxies in EAP 7.x must be configured as outbound-socket-binding:

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    ...
    <outbound-socket-binding name="proxy1">
        <remote-destination host="xx.xx.xx.xx" port="6666"/>
    </outbound-socket-binding>
    <outbound-socket-binding name="proxy2">
        <remote-destination host="yy.yy.yy.yy" port="6666"/>
    </outbound-socket-binding>
</socket-binding-group>

For EAP 6.4 and 7.x, modcluster.balancer.name is the name of the different balancers, configured as property (e.g.: in domain configuration, configured in server-group or in server). As the apache config above, the values will be balancer_1 and balancer_2.

The applications deployed in each balancer could have the same contexts (all or some), but the requests will be sent to the correct one depending on the request URL, as the Apache configuration.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments