Tag: Apache

Using mod_cluster with JBoss AS 7.1 cluster

We have seen how to create clusters in standalone, domain with multicast and unicast protocols also which have been listed below. However in this article we would be seeing how to use mod_cluster with our created clusters in both standalone and domain mode.

Following are the list of article we have created till now for creating a cluster in JBoss AS 7.1.1 Final till now

  1. How to create cluster in JBoss AS 7.1 in standalone mode?
  2. How to create cluster in JBoss AS 7.1 in domain mode?
  3. Creating TCP cluster in JBoss AS 7.1 in standalone mode?

Again we would be using JBoss AS 7.1.1.Final for this article as well so that we are all on the same page, as few things have been change from JBoss AS 7.0 to JBoss AS 7.1.

Changes taken place:

  1. AJP connector is enabled by default in standalone-ha.xml , standalone-full-ha.xml and domain.xml for ha and full-ha profile.
  2. Instead of JVMRoute, now we have to use instance-id

Using mod_cluster with JBoss AS 7.1 cluster

For this we would have to modify from both side Apache as well as JBoss AS7 side, hence lets see the configuration one at a time

Apache side configuration

Lets see what all configuration has to be made from Apache side

  1. You can configure mod_cluster from the below article, just follow the “Apache side configuration” part only
  2. How to configure mod_cluster with JBoss ?

  3. In the above article you can just add the IP_ADDRESS of the box on which Apache is running which is in the Step-3 something as shown below
  4. ############### 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
    
    Listen 1.1.1.1:80
    
    <VirtualHost 1.1.1.1: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
              ManagerBalancerName mycluster
              ServerAdvertise On
    </VirtualHost>
    ############### mod_cluster Setting - ENDED ###############
    

JBoss side configuration

Now we would see what all changes we have to be done from JBoss end in standalone and domain files

Standalone

  1. First you would have to follow all the steps given in the link – How to create cluster in JBoss AS 7.1 in standalone mode? and then make the below changes in all the standalone servers.
  2. Give a unique name in the server element, as shown below .
  3. standalone-node1

    <server name="standalone-node1" xmlns="urn:jboss:domain:1.2">
    

    standalone-node2

    <server name="standalone-node2" xmlns="urn:jboss:domain:1.2">
    
  4. As told earlier you would have to add the instance-id attribute in web subsystem as shown below in both the standalone nodes.
  5.         <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" instance-id="${jboss.node.name}" native="false">
                <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
                <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>
                .
                .
                .
            </subsystem>
    
  6. Last you just have to add the proxy-list in the attribute in mod-cluster-config of modcluster subsystem, which would be having IP Address and Port on which your Apache server is running so that JBoss server can communicate with it, as shown below in both the standalone nodes.
  7.         <subsystem xmlns="urn:jboss:domain:modcluster:1.0">
                <mod-cluster-config advertise-socket="modcluster" proxy-list="1.1.1.1:80">
                .
                .
                .
                </mod-cluster-config>
            </subsystem>
    

If everything is configured properly you can hit the URL = http://1.1.1.1/mod_cluster-manager which would show similar below screen. Below image is showing when cluster is been made in on the same box using standalone mode

mod_cluster for Standalone on the same box

Domain

  1. First you would have to follow all the steps given in the link – How to create cluster in JBoss AS 7.1 in domain mode? and then make the below changes in your domain file.
  2. We would have to add the instance-id attribute in web subsystem as shown below in domain.xml for the respective profile ha and full-ha which is been used.
  3.             <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" instance-id="${jboss.node.name}" native="false">
                    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
                    <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>
                     .
                     .
                     .
                </subsystem>
    
  4. Last you just have to add the proxy-list in the attribute in mod-cluster-config of modcluster subsystem, which would be having IP Address and Port on which your Apache server is running so that JBoss server can communicate with it, as shown below in domain.xml for the respective profile ha and full-ha which is been used.
  5.         <subsystem xmlns="urn:jboss:domain:modcluster:1.0">
                <mod-cluster-config advertise-socket="modcluster" proxy-list="1.1.1.1:80">
                .
                .
                .
                </mod-cluster-config>
            </subsystem>
    

If everything is configured properly you can hit the URL = http://1.1.1.1/mod_cluster-manager which would show similar below screen. Below image is showing when cluster is been made in on the same box as well as in remote box using domain mode.

Same Box

mod_cluster for Domain mode on the same box

Remote Box

mod_cluster for Domain mode on Remote box

Testing

In all our previous article we had asked you to use one of our application called ClusterWebAp, this is the time when we would be testing if our cluster is working properly with mod_cluster configuration.

  1. Once everything thing is been configured and have been started up properly you can hit the application using Apache URL as shown below and you would see something like in the snap-shot
  2. http://1.1.1.1/ClusterWebApp
    

    ClusterWebApp

  3. Suppose the first request goes to standalone-node2 , you can see there is a session-id which is been generated. Now you just have to shutdown your standalone-node2 and then click on the link Click Here to move to nextPage sessionCheck.jsp on the same page.
  4. Once you click on the link, you will notice that the request has been served by the standalone-node1 this time as node2 had been brought down, but the session-id remains the same which was created earlier having the same timestamp as shown below
  5. Session Replication

With this test it is clear that our cluster is working fine as the session replication is happening properly on JBoss using mod_cluster.

Issues you might face

If you have not given the instance-id in the domain.xml file for ha or full-ha and have a step up a cluster which is having a mod_cluster in front of them you might get the following error in the logs.

[Server:ha-server-1] 20:29:36,429 ERROR [org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Error [MEM: MEM: Old node still exist: {4}] sending command CONFIG to proxy 10.10.10.10:80, configuration will be reset
[Server:ha-server-2] 20:29:37,426 ERROR [org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Error [MEM: MEM: Can't read node: {4}] sending command STATUS to proxy 10.10.10.10:80, configuration will be reset
[Server:ha-server-2] 20:29:47,432 ERROR [org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Error [MEM: MEM: Old node still exist: {4}] sending command CONFIG to proxy 10.10.10.10:80, configuration will be reset
[Server:ha-server-1] 20:29:56,441 ERROR [org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Error [MEM: MEM: Can't read node: {4}] sending command STATUS to proxy 10.10.10.10:80, configuration will be reset

For this you just have to follow the step-2 of Domain configuration, which would fix this issue.


Custom error pages in Apache for JBoss AS7

In this article we would show a simple demonstration of using our own custom error pages which would be severed from Apache side with the static contents like image/HTML/etc files, however here we would using images and HTML pages as a repository. Custom error pages are been required by everyone in there production environments, becasue one would not like there clients to see the default error pages when some issue comes from the server side or by mistake your clients tries to access a non-existing page in your application, hence with this article you can show your own custom error pages using Apache for JBoss AS 7

We would be using the standalone mode for this article and in JBoss AS 7.1.0.CR1b version we have a different xml file called standalone-full.xml which would be used with Apache mod_jk.

Now there are few things which has to be noted here to achieve this configuration

  1. Add system-properties to give the jvmRoute
  2. Enable AJP protocol and add AJP port

Custom error pages in Apache for JBoss AS7

For this we would have to modify from both side Apache as well as JBoss AS7 side, hence lets see the configuration one at a time

Apache side configuration

Lets see what all configuration has to be made from Apache side

  1. You can configure mod_jk from the below article
  2. Configuring mod_jk to connect to JBoss
    In the following section of the above link: “Apache WebServer Configuration Part”

  3. In the above article you just have to replace the Step-8 by the following content
  4. ##### JBOSS #############
    LoadModule jk_module modules/mod_jk.so
     
    # Include mod_jk's specific configuration file
    Include conf/mod_jk.conf
    
    Listen 10.10.10.10:80
    
    # (1) Setting up the Alias for the "error" directory
    Alias /error/ "/etc/httpd/www/error/"
    
    # (2) Mapping the error codes with custom error pages
    ErrorDocument 404 /error/404_ErrorPage.html
    ErrorDocument 503 /error/MaintenancePage.html
    
    <VirtualHost 10.10.10.10:80>
    
      # (3) All the application context would go to "nodeA"
      JkMount /* nodeA
       
      # (4) Setting error code 404 for "MyApp" application
      JkMount /MyApp/* nodeA;use_server_errors=404
    
      # Static files in the examples webapp are served by Apache
      Alias /images /etc/httpd/www/html/MyApp/images
     
      # All requests go to nodeA
      JkMount /* nodeA
     
      # Serve html, jpg, png etc using httpd
      JkUnMount /*.html  nodeA
      JkUnMount /*.png  nodeA
      JkUnMount /*.jpg  nodeA
      JkUnMount /*.gif  nodeA
    
    </VirtualHost>
    ###########################
    

    Where: 10.10.10.10:80 is the “IP_ADDRESS:PORT” of your Apache box

  5. And in the Step-10 of above article replace it by the following content
  6. ##### JBOSS #############
    # Define list of workers that will be used for mapping requests
    worker.list=nodeA,status
    
    # Status worker for managing load balancer
    worker.status.type=status
    
    # Define nodeA modify the host as your host IP or DNS name.
    worker.nodeA.port=8009
    worker.nodeA.host=20.20.20.20
    worker.nodeA.type=ajp13
    worker.nodeA.ping_mode=A
    ###########################
    

    Where: 20.20.20.20 is the “binding address” of your JBoss AS7 on which it is running and “8009” is the AJP port

So with the above configuration you can see that

  1. In the path “/etc/httpd/www/error/” would have all custom error pages with an alias “error”
  2. Mapping the custom error pages with the respective error codes
  3. All the application would be severed by “nodeA”
  4. If someone tires to access some page which is not present in the application would get our 404 custom error page.

Following are the custom error pages which we have created. Hope you like them.

MaintenancePage.html

<html>
  <head>
     <title>Middleware Magic - 503 Custom Error Page</title>
  </head>
  <body>
	<center><font color=maroon>
		<h1>Custom Maintenance Page</h1>
		<h2>Oops...You caught us down !!!.<br><br>
		<img src="/images/down.jpg"/><br><br>
		Please try after sometime...</h2><br>
		<img src="/images/MiddlewareMagic.png" width="150" height="150" />
		<h1>Middleware Magic</h1>
	        </font>
	</center>
   </body>
</html>

404_ErrorPage.html

<html>
  <head>
     <title>Middleware Magic - 404 Custom Error Page</title>
  </head>
  <body>
	<center><font color=maroon>
		<h1>404 Error - Page Not Found</h1>
		<h2>Look's like your yesterday's HANGOVER has not gone...<br><br>
		<img src="/images/hangover.jpg" width="200" height="200"/><br><br>
		Try accessing the correct page !!!</h2><br>
		<img src="/images/MiddlewareMagic.png" width="150" height="150"/>
		<h1>Middleware Magic</h1>
		</font>
	</center>
  </body>
</html>

JBoss AS7 side configuration

Lets see what all configuration has to be made from JBoss AS7 side

  1. As described earlier we would have to add the system-properties to give the jvmRoute which can be done by adding the “system-propertie” tag just after the extensions gets over, as shown below
  2. <extensions>
    .
    .
    </extensions>
    
    <!-- Below system properties tag has been added -->
    <system-properties>
    	<property name="jvmRoute" value="nodeA"/>
    </system-properties>
    
  3. By default in JBoss AS7 AJP protocol and port are not their, hence we would have to enable and add them as shown below
  4. Enabling AJP protocol

    <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
    	<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
     <!-- We have to enable the AJP protocol by adding below line -->
    	<connector name="ajp" protocol="AJP/1.3" socket-binding="ajp" enabled="true"/>  
    

    Adding AJP port

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    	<socket-binding name="http" port="8080"/>
    <!-- We have to add the AJP port by adding below line -->
    	<socket-binding name="ajp" port="8009"/>  
    

The configuration has been done from both the ends, now comes the application which would be used to test the above configuration which have done.

Steps to create a test application

  1. Create a folder called MyApp
  2. In “MyApp” folder create index.jsp file and WEB-INF folder which has web.xml inside it and copy the below code in “web.xml”
  3. <web-app>
       <welcome-file-list>
           <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
    </web-app>
    
  4. In “index.jsp” file copy the below code in it
  5. <html>
    	<head>
    		<title>Middleware Magic - MyApp Static Page Test</title>
    	</head>
    	<body>
    		<center><h3><font color=maroon>This page coming from JBoss AS7....</font></h3>
    		<h1><font color=maroon>but image is coming from Apache!!! </font></h1>
    		<img src="/images/MiddlewareMagic.png"/>
    		<h1><font color=maroon>Middleware Magic </font></h1></center>
    	</body>
    </html>
    

    NOTE: You would have to give the image name with the extension which is present in the path “/etc/httpd/www/html/MyApp/images” from Apache side.

  6. Once you have done with all this you now just have to create an WAR file out of this, for that you need to be in the MyApp folder and run the below command (make sure you have setted the java/bin in your PATH). Note: you would have to give the (.) dot at last as well
  7. MyApp] jar -cvf MyApp.war .
    

Testing

Now just start your Apache and JBoss AS7 by keeping the “MyApp.war” in “/standalone/deployments” folder and hit the Apache URL with the context root of the application.

http://10.10.10.10:80/MyApp

You will notice that the JSP file is been picked up from JBoss AS7 but the image is been picked up from Apache which is getting displaced on the page, this means that the static content is been served from Apache.

Good our application is working fine, now lets try if your custom error pages work. Hence try hitting the below URL to check the custom 404 error page

http://10.10.10.10:80/MyApp/a.jsp

That’s working, let try the custom maintenance page, for that we would have to shut-down the JBoss AS7 server which would give us 503 error which means that the backend server is down, which we do sometime if we need to do a maintenance on the JBoss sever side. Thus bring down your running JBoss AS 7 server and hit the below link

http://10.10.10.10:80/MyApp


Apache as static content repository for JBoss AS7

In this article we would show a simple demonstration of using Apache as a repository for caching static contents like image/HTML/etc files, however here we would use image as a repository.This helps us in improving the performance of the backend servers as all the static contents would be served by Apache itself and all the dynamic contents can be served backend server JBoss AS7.

We would be using the standalone mode for this article and in JBoss AS 7.1.0.CR1b version we have a different xml file called standalone-full.xml which would be used with Apache mod_jk.

Now there are few things which has to be noted here to achieve this configuration

  1. Add system-properties to give the jvmRoute
  2. Enable AJP protocol and add AJP port

Configuring Apache as a static content repository

For this we would have to modify from both side Apache as well as JBoss AS7 side, hence lets see the configuration one at a time

Apache side configuration

Lets see what all configuration has to be made from Apache side

  1. You can configure mod_jk from the below article
  2. Configuring mod_jk to connect to JBoss
    In the following section of the above link: “Apache WebServer Configuration Part”

  3. In the above article you just have to replace the Step-8 by the following content
  4. ##### JBOSS #############
    LoadModule jk_module modules/mod_jk.so
     
    # Include mod_jk's specific configuration file
    Include conf/mod_jk.conf
    
    Listen	10.10.10.10:80
    NameVirtualHost	10.10.10.10:80
    
    <VirtualHost 10.10.10.10:80>
    
      # Static files in the examples webapp are served by Apache
      Alias /images /etc/httpd/www/html/MyApp/images
    
      # All requests go to nodeA
      JkMount /* nodeA
    
      # Serve html, jpg, png etc using httpd
      JkUnMount /*.png  nodeA
      JkUnMount /*.html  nodeA
      JkUnMount /*.jpg  nodeA
      JkUnMount /*.gif  nodeA
    
    </VirtualHost>
    ###########################
    

    Where: 10.10.10.10:80 is the “IP_ADDRESS:PORT” of your Apache box

  5. And in the Step-10 of above article replace it by the following content
  6. ##### JBOSS #############
    # Define list of workers that will be used for mapping requests
    worker.list=nodeA,status
    
    # Status worker for managing load balancer
    worker.status.type=status
    
    # Define nodeA modify the host as your host IP or DNS name.
    worker.nodeA.port=8009
    worker.nodeA.host=20.20.20.20
    worker.nodeA.type=ajp13
    worker.nodeA.ping_mode=A
    ###########################
    

    Where: 20.20.20.20 is the “binding address” of your JBoss AS7 on which it is running and “8009” is the AJP port

So here you can see that in the path “/etc/httpd/www/html/MyApp/images” would have all the images for an application called “MyApp” and the paths alias is been giving as “/images” which would used in application.

JBoss AS7 side configuration

Lets see what all configuration has to be made from JBoss AS7 side

  1. As described earlier we would have to add the system-properties to give the jvmRoute which can be done by adding the “system-propertie” tag just after the extensions gets over, as shown below
  2. <extensions>
    .
    .
    </extensions>
    
    <!-- Below system properties tag has been added -->
    <system-properties>
    	<property name="jvmRoute" value="nodeA"/>
    </system-properties>
    
  3. By default in JBoss AS7 AJP protocol and port are not their, hence we would have to enable and add them as shown below
  4. Enabling AJP protocol

    <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
    	<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
     <!-- We have to enable the AJP protocol by adding below line -->
    	<connector name="ajp" protocol="AJP/1.3" socket-binding="ajp" enabled="true"/>  
    

    Adding AJP port

    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    	<socket-binding name="http" port="8080"/>
    <!-- We have to add the AJP port by adding below line -->
    	<socket-binding name="ajp" port="8009"/>  
    

The configuration has been done from both the ends, now comes the application which would be used to test the above configuration which have done.

Steps to create a test application

  1. Create a folder called MyApp
  2. In “MyApp” folder create index.jsp file and WEB-INF folder which has web.xml inside it and copy the below code in “web.xml”
  3. <web-app>
       <welcome-file-list>
           <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
    </web-app>
    
  4. In “index.jsp” file copy the below code in it
  5. <html>
    	<head>
    		<title>Middleware Magic - MyApp Static Page Test</title>
    	</head>
    	<body>
    		<center><h3><font color=maroon>This page coming from JBoss AS7....</font></h3>
    		<h1><font color=maroon>but image is coming from Apache!!! </font></h1>
    		<img src="/images/MiddlewareMagic.png"/>
    		<h1><font color=maroon>Middleware Magic </font></h1></center>
    	</body>
    </html>
    

    NOTE: You would have to give the image name with the extension which is present in the path “/etc/httpd/www/html/MyApp/images” from Apache side.

  6. Once you have done with all this you now just have to create an WAR file out of this, for that you need to be in the MyApp folder and run the below command (make sure you have setted the java/bin in your PATH). Note: you would have to give the (.) dot at last as well
  7. MyApp] jar -cvf MyApp.war .
    

Testing

Now just start your Apache and JBoss AS7 by keeping the “MyApp.war” in “/standalone/deployments” folder and hit the Apache URL with the context root of the application.

http://10.10.10.10:80/MyApp

You will notice that the JSP file is been picked up from JBoss AS7 but the image is been picked up from Apache which is getting displaced on the page, this means that the static content is been served from Apache.


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