Tag: Apache

How to configure mod_cluster with JBoss ?


Like mod_jk, mod_cluster is also a httpd based load balancer which uses a communication channel to forward requests from the httpd to one of a set of application server nodes. So the question comes Why mod_cluster ? To answer this question we will let you know few advantages of mod_cluster over mod_jk and other httpd-based load balancers.

Hence in this article we would share you why should one use mod_cluster ? and how to configure mod_cluster with JBoss ? Hopping all our subscribers would take the advantage of this article and would help them to choose which is the best option for httpd based load balancer for there requirement.

Why should one use mod_cluster ?

  • Dynamic configuration:
  • Server side load balance:
  • AJP is optional:
  • Web application lifecycle control:

To know all the Advantages and Great features of mod_cluster refer to :

Steps to configure mod_cluster with JBoss

I have divided this configuration into two parts to, so that it would be much more easier to understand follow the steps. Here the following are the two parts

  1. Apache side configuration
  2. JBoss side configuration

Apache side configuration

  1. Download the required binaries for your OS from below link, example for RHEL x64 bit its [dynamic libraries linux2-x64]
  2. http://www.jboss.org/mod_cluster/downloads/1-1-0.html

  3. Copy following .so files to your “<Apache_Home>/modules” folder.
  4. mod_proxy.so
    mod_proxy_ajp.so
    mod_slotmem.so
    mod_manager.so
    mod_proxy_cluster.so
    mod_advertise.so

  5. Edit your httpd.conf (i.e. /conf/http.conf) and add following lines at the bottom of the file. However this virtualhost setting is a sample, you might have to make some changes as per your own environment.
  6. ############### mod_cluster Setting - STARTED ###############
    LoadModule slotmem_module modules/mod_slotmem.so
    LoadModule manager_module modules/mod_manager.so
    LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
    LoadModule advertise_module modules/mod_advertise.so
    <VirtualHost *:80>
    	<Directory />
    		Order deny,allow
    		Allow from all
    	</Directory>
    	<Location /mod_cluster_manager>
    		SetHandler mod_cluster-manager
    		Order deny,allow
    		Allow from all
    	</Location>
    	KeepAliveTimeout 60
    	MaxKeepAliveRequests 0
    	ManagerBalancerName testcluster
    	AdvertiseFrequency 5
    </VirtualHost>
    ############### mod_cluster Setting - ENDED ###############
    

    NOTE:

    You have to COMMENT the follwoing module (i.e. mod_proxy_balancer.so) in “httpd.conf” file, or else you would get error while starting your Apache, this is been done because we are now using mod_proxy_cluster.so instead of mod_proxy_balancer.so

    #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    
  7. Restart Apache.
  8. NOTE:

    You have to do the following things before starting the APACHE

    Command:

    setenforce 0
    

    The above command will disable SE Linux for your current running session. However if you want to disable it permanently then follow the below steps

    vi /etc/selinux/config
    
    #SELINUX=enforcing (comment this line and add the below line)
    SELINUX=disabled
    
    

    May be this would need to restart your system, this way you will be sure that the changes have taken place.

JBoss side configuration

  1. Copy “mod-cluster.sar” from “/home/testusr/AS6/mod_cluster” to “/server/cluster_node1/deploy”
  2. Edit “mod-cluster-jboss-beans.xml” from “<JBOSS_HOME>/server/cluster_node1/deploy/mod-cluster.sar/META-INF/mod-cluster-jboss-beans.xml” so that it has following.
  3. BELOW

    <bean name="HAModClusterConfig" class="org.jboss.modcluster.config.ha.HAModClusterConfig" mode="On Demand">
    
    <!-- START Comma separated list of address:port listing the httpd servers where mod_cluster is running. -->
        <property name="proxyList">${jboss.modcluster.proxyList:localhost:80}</property>
        <property name="domain">${jboss.Domain:DefaultDomain}</property>
    <!-- END Comma separated list of address:port listing the httpd servers where mod_cluster is running. -->
    
  4. Edit “server.xml” from “/server/all/deploy/jbossweb.sar/server.xml” so that it has following lines.
  5. <!-- START mod_cluster setting -->
         <Listener  className="org.jboss.web.tomcat.service.deployers.MicrocontainerIntegrationLifecycleListener" delegateBeanName="HAModClusterService"/>
    <!-- END mod_cluster setting -->
    

    NOTE:
    Make sure you add above line BEFORE/ABOVE

       <Service name="jboss.web">
    

    and

    <!-- START mod_cluster setting -->
         <Engine name="jboss.web" defaultHost="localhost" jvmRoute="${jboss.jvmRoute}">
    <!-- END mod_cluster setting -->
    

    NOTE:
    Make sure you replace above line instead of this line

          <Engine name="jboss.web" defaultHost="localhost">
    
  6. Edit “jboss-beans.xml” (/server/all/deploy/jbossweb.sar/META-INF/jboss-beans.xml) and add the below line in “bean” element
  7. <depends>HAModClusterService</depends>
    

Command to start the servers

Below is the command to start the serves in a cluster which are on the same Box/Physical Machine

NODE-1:

./run.sh -c cluster_node1 -g ClusterA -u 239.255.100.101 -b localhost -Djboss.Domain=test -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-01 -Djboss.jvmRoute="node1"

NODE-2:

./run.sh -c cluster_node2 -g ClusterA -u 239.255.100.101 -b localhost -Djboss.Domain=test -Djboss.messaging.ServerPeerID=2 -Djboss.service.binding.set=ports-02 -Djboss.jvmRoute="node2"

URL to hit

http://localhost/mod_cluster_manager

Regards,

Middleware Magic


Configuring mod_jk to connect to JBoss

Hi,

Here is a simple step by step procedure to connect to JBoss instance for load balancing purpose through apache webserver. In most of the production environments this is the most common need.

The prerequisite for this exercise is to have the the Apache WebServer installed already in your Machine and the JBoss should be installed in your environment. The “mod_jk” module can be downloaded later to work on this setup. If you want to download the apache software and the mod_jk then you can refer to the link mentioned in the Step6):

JBoss Cluster Creation/Configuration Part:

Step1). As “all” and “production” profiles which are present inside the “E:jboss-AS6-5.1jboss-asserver” location are by default clustering enabled so you can chose any one of them to create your own clustered node. In this exercise we will use “all” profile to create JBoss Clusters.

So first copy the “all” profile and paste it in the same location “E:jboss-AS6-5.1jboss-asserver” with some different name like “all_node1” and “all_node2”. like this your 2 JBoss Clustered Nodes are ready.

Step2). Now open the “server.xml” file present inside the “E:jboss-AS6-5.1jboss-asserverall_node1deployjbossweb.sar” location and then add the “jvmRoute” attribute of the Engine Tag like following:By default the line which you are going to change will look like following:
=============By default it will look like below==================

<Engine name="jboss.web" defaultHost="localhost">

=============After Change it will look like below==================

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">

Step3). Same changes we need to do for “all_node2” profile as well. So open the “server.xml” file present inside the “E:jboss-AS6-5.1jboss-asserverall_node2deployjbossweb.sar” location and then add the “jvmRoute” attribute of the Engine Tag like following:
=============By default it will look like below==================

<Engine name="jboss.web" defaultHost="localhost">

=============After Change it will look like below==================

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node2">

Why We need “jvmRoute”?

jvmRoute Identifier must be used in load balancing scenarios to enable session affinity. The identifier, which must be unique across all Tomcat 6 servers which participate in the cluster, will be appended to the generated session identifier, therefore allowing the front end proxy to always forward a particular session to the same Tomcat 6 OR JBoss instance.

More information regarding this attribute can be found in the following link:
http://tomcat.apache.org/tomcat-6.0-doc/config/engine.html#Common_Attributes

Step4). Also please make sure that the AJP Connector Tag is uncommented in “E:jboss-AS6-5.1jboss-asserverall_node2deployjbossweb.sarserver.xml” file for both “all_node1” & “all_node2” profiles, Because the communication between Apache and JBoss will happen through this AJP connector port. Like following:

      <!-- A AJP 1.3 Connector on port 8009 -->
      <Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
         redirectPort="8443" />

Step5). Now start Both the JBoss Instances by running the following command from the following dir “E:jboss-AS6-5.1jboss-asbin”:

run.bat -c all_node1 -b 0.0.0.0 -g ClusterA -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=1
run.bat -c all_node2 -b 0.0.0.0 -g ClusterA -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=2

Here following are the meaning of the flags which we have used :
-c = The jboss profile which we want to start

-g = The name of the cluster. The same name of the cluster should be used by the profiles which want to join the same cluster formation.

-Djboss.service.binding.set = The advantage of this way is you don’t have to take (and maintain) a separate copy of the all folder if you want to, say, start up multiple instances of JBoss running as a cluster. For more information on this system property please refer to the following : http://community.jboss.org/wiki/ConfigurePorts

-Djboss.messaging.ServerPeerID = Each node must have a unique ServerPeerID for clustering to work!. It can be any unique integer value among all the cluster members. Means every cluster node should have a unique peer ID.

-b = The bind address in which you want to run your profile. o.o.o.o represents it will listen to all the IP Addresses associated with that box. better if we can specify a particular “IP Address” or “localhost” there rather than using “0.0.0.0”

So suppose if you are running your JBoss on two separate physical boxes which has different IP Addresses like 10.10.10.10 and 20.20.20.20 then please run the servers like following

run.bat -c all_node1 -b 10.10.10.10 -g ClusterA -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=1
run.bat -c all_node2 -b 20.20.20.20 -g ClusterA -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=2

Apache WebServer Configuration Part:

Step6). Download & Install the apache webserver from the following link along with the “mod_jk” file:
http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Web_Platform/5/html/Administration_And_Configuration_Guide/clustering-http.html#clustering-http-modjk

Step7). Now paste the “mod_jk.so” file inside the modules directory of your apache which may be “C:Program FilesApache GroupApache2modules”

Step8). Now add the following line of configuration somewhere at the bottom inside your “C:Program FilesApache GroupApache2confhttpd.conf” file to include the mod_jk configuration file:

##### JBOSS #############
LoadModule jk_module modules/mod_jk.so

# Include mod_jk's specific configuration file
Include conf/mod_jk.conf
###########################

Step9). Now create a file with name “mod_jk.conf” inside the directory “C:Program FilesApache GroupApache2conf” as following:

##### JBOSS #############
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat  "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
JkMount /* failover

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
#JkMountFile conf/uriworkermap.properties

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm

# Add jkstatus for managing runtime data
<Location /jkstatus/>
    JkMount status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
###########################

Step10). Now create another most important file “worker.properties” inside “C:Program FilesApache GroupApache2conf” to tell apache to load balance between what all nodes of the JBoss clusters:

##### JBOSS #############
# Define list of workers that will be used
# for mapping requests
worker.list=failover
#,status

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8209
worker.node2.host=20.20.20.20
worker.node2.type=ajp13
worker.node2.ping_mode=A
worker.node2.lbfactor=1

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8109
worker.node1.host=10.10.10.10
worker.node1.type=ajp13
worker.node1.ping_mode=A
worker.node1.lbfactor=1

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node2,node1
worker.loadbalancer.sticky_session=False
worker.list=loadbalancer

# Status worker for managing load balancer
#worker.status.type=status
###########################

NOTE: Make sure that you are setting the correct “Hostname” and “AJP Port” for your JBoss in the above file.

Step 11). Now restart your apache server and then hit the following URL to access the JBoss:

http://localhost/jmx-console
OR
http://localhost/admin-console

.
.
Thanks
Middleware Magic


Using mod_jk to access multiple applications

In this article we would show you how to configure mod_jk so that one can access multiple applications using single Apache in front of JBoss application servers we would be using AS6. Many companies run n-number of applications and they might be using different Apache webservers for each applications to deal with it, hence hope this article would help you guys so that you can work with a single Apache having mod_jk to access multiple applications.

Here we would be taking the below examples in which we have a two different applications and one having a different context which would cover a huge ground for a combination of applications used by companies.

Examples

* App1 should work with url: http://abc.com/test
* App2 should work with url: http://abc.com
* App3 should work with url: http://xyz.com

Steps to configure mod_jk to access multiple applications

1. In “worker.properties” file would have the following entries

worker.list=App1,App2,App3

# Define App1
worker.App1.port=8009
worker.App1.host=localhost
worker.App1.type=ajp13
worker.App1.lbfactor=1

# Define App2
worker.App2.port=8109
worker.App2.host=localhost
worker.App2.type=ajp13
worker.App2.lbfactor=1

# Define App3
worker.App3.port=8209
worker.App3.host=localhost
worker.App3.type=ajp13
worker.App3.lbfactor=1

2. In “httpd.conf” file following should be the entries

NameVirtualHost *.80 

<VirtualHost *:80>
    ServerName abc.com
    DocumentRoot "/etc/httpd/www/html"
    DirectoryIndex home.html
    ErrorLog "/etc/httpd/conf/abc-error_log"
    CustomLog "/etc/httpd/conf/abc-access_log" common
    
    #Mount
    JkMount /* abc
    JkMount /abcd* abcd
</VirtualHost>

<VirtualHost *:80>
    ServerName xyz.com
    DocumentRoot "/etc/httpd/www/html"
    DirectoryIndex index.html
    ErrorLog "/etc/httpd/conf/xyz-error_log"
    CustomLog "/etc/httpd/conf/xyz-access_log" common

    #Mount
    JkMount /* xyz
</VirtualHost>

3. However to make sure that, when you hit “http://abc.com” and “http://xyz.com” URL’s the receptive applications comes up directly you should make sure that both the applications should have the following entries in there “/AppX/WEB-INF/jboss-web.xml” file

<jboss-web>
   <context-root>/</context-root>
</jboss-web>

And in there respective JBoss nodes “/NodeX/deploy/ROOT.war/WEB-INF/jboss-web.xml” file should add the following entry.
java:/jaas/jmx-console

<jboss-web>
 <security-domain>java:/jaas/jmx-console</security-domain>
 <context-root>/root</context-root>                         <!-- THIS LINE ADDED  -->
</jboss-web>

Example:
– For App-2 the JBoss Node-2 named as “node-2”
Path:
/node-2/deploy/abc.war/WEB-INF/jboss-web.xml – should have the context-root as “/”
/node-2/deploy/ROOT.war/WEB-INF/jboss-web.xml – should have context-root as “/root”

– For App-3 the JBoss Node-3 named as “node-3”
Path:
/node-3/deploy/xyz.war/WEB-INF/jboss-web.xml – should have context-root as “/”
/node-3/deploy/ROOT.war/WEB-INF/jboss-web.xml – should have context-root as “/root”

Thus now when you hit the above given URLs in the examples it would show you the respective application and that too using a single Apache in front of JBoss.


Copyright © 2010-2012 Middleware Magic. All rights reserved. |