Welcome!

Java Authors: Michael Meiner, Carmen Gonzalez, Trevor Parsons, Elizabeth White, Pat Romanski

Related Topics: Java, Cloud Expo, Apache

Java: Article

Dynamic Clustering for J2EE Cloud Environments

Cloud computing is one of the emerging paradigms in today's computing world

Cloud computing is one of the emerging paradigms in today's computing world. One of the main advantages of migrating to the cloud is its elastic nature. Elasticity allows dynamic provisioning and de-provisioning of resources according to the application's workload requirement.

In a traditional on-premise J2EE infrastructure, information about the application server and web server resources are available during deployment. Clustering of such an infrastructure to achieve scalability is much simpler since the information about resources is known beforehand. But in a cloud environment, because of its elastic nature, resources get provisioned and de-provisioned dynamically based on the workload. So a j2ee cloud environment has challenges like reconfiguring automatically for the addition/removal of application server instances to/from the cluster. One solution from the open source space is to use Apache Httpd web server with mod_cluster load balancing module and JBoss application server.

The article will discuss the features of mod_cluster which enable it to operate in a cloud environment and also the steps to set up a highly scalable J2EE cloud environment in your lab.

Introduction to mod_cluster
mod_cluster is an extension of the Apache httpd mod_proxy load balancing module and can balance http requests across multiple instances of JBoss Application Server, JBoss Web standalone, or Tomcat. The unique feature of mod_cluster is that once the initial configuration is done, there is no need of any manual configuration changes for adding or removing JBoss AS or Tomcat instances.

mod_cluster uses two communication channels for its working. It uses ajp, http or https to forward requests from httpd to one of the application server nodes. The backward channel is used by the application server nodes to send server side information to the httpd side and is the key differentiator for mod_cluster with respect to other load balancing modules. This channel sends real time information about load balancing factors for each node and application life cycle events.

Some of the key features of mod_cluster that enable it to be used in cloud environments are

Dynamic configuration
Common httpd based load balancers like mod_jk and mod_proxy require the configuration of workers (application servers) at the httpd side. So if you want to add a new worker, you will have to change the configuration in httpd side and restart the proxy. This is an overhead in case of large or dynamically varying clusters like in cloud environments.

But with mod_cluster the proxy information is maintained in the application server side through a static list or through the advertise mechanism (using mod_advertise) . As the workers start, the listeners receive multicast pings which contain the host and port information about the proxies. Now the workers can send events to the detected proxies and the proxies auto configure themselves to balance request between the nodes.

Dynamic determination of load balancing factor
In common httpd based load balancers, the ratio in which load is distributed among the workers is determined by a static factor we provide at the httpd load balancer configuration. But in the case of mod_cluster the load balancing factor is determined at the application server side based on the real time values monitored at runtime. Load computation is pluggable and you can write your own LoadMetric based on the metric you want in addition to the default load metrics.

Fine grained web application life cycle
In the case of mod_cluster, the applications deployed in the application server side are registered with the httpd side through the Mod-Cluster Management protocol. So the http side has information about which all applications are deployed in which instances and transfers the requests only to the nodes which have the requested application. Since the proxies have information on the applications deployed on each of the workers, we can keep highly sensitive applications on our private cloud and move lesser critical applications to some public provider. This enables us to scale up without compromising security as the data sensitive applications will be in our local premises only . For example in a shopping cart scenario browsing the catalog can go into the public cloud and sensitive requirements like payments can stay in company's private cloud.

The following section describes how we can set up a highly scalable j2ee environment using vmware(or any other private cloud solution like Eucalyptus or Open Nebula) in your lab setup.

Environment Set-Up
We have VMware vCenter server setup in one of the machines and connected to an ESXi host. The discussion is based on the assumption that the reader knows how to create a virtual machine and install guest operating system in a vmware environment. Our virtual machine has CENTOS 5.4 installed in it.

To set up dynamic cluster in cloud, we need minimum of two instances:

  1. Apache httpd + mod_cluster
  2. JBoss 5.1 application server with mod_cluster

Now we can look into creating each of these images/templates with necessary startup scripts in details. These steps can be done in any of the CentOS 5 installed machine or virtual machines.

Creating Apache httpd image
Step 1. Create a base virtual machine with centos 5.x as the guest operating system.
Refer creating a virtual machine and installing guest os for VMWare virtual machine creation.

Step 2. Install Apache httpd and mod_cluster in the virtual machine
Download the apache httpd integrated with latest mod_cluster distribution here. To install httpd with mod_cluster, move the distribution to the vm and extract mod_cluster-1.1.xxx-linux2-x86-ssl.tar.gz file using the following command

tar xvf mod-cluster-1.1.0.xxx-linux2-x86-ssl.tar.gz

This by default installs httpd with required mod_cluster modules in /opt/jboss directory.

Step 3. Configuring mod_cluster at httpd side
The httpd configuration file will be httpd.conf which is located in /opt/JBoss/httpd/httpd/conf. From mod_cluster1.1.0CR2 mod_cluster comes with some quick start values.

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

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

The above configuration specifies the extra modules required for httpd with mod_cluster. If you are adding mod_cluster to the existing httpd installation, you have to download the modules and add the above configuration to httpd.conf file.

# MOD_CLUSTER_ADDS

# Adjust to you hostname and subnet.

<IfModule manager_module>

Listen *:6666

ManagerBalancerName mycluster

<VirtualHost *:6666>

<Directory />

Order deny,allow

Deny from none

Allow from all

</Directory>

KeepAliveTimeout 300

MaxKeepAliveRequests 0

#ServerAdvertise on http://@IP@:6666

AdvertiseFrequency 5

#AdvertiseSecurityKey secret

#AdvertiseGroup @ADVIP@:23364

<Location /mod_cluster_manager>

SetHandler mod_cluster-manager

Order deny,allow

Deny from none

Allow from all

</Location>

</VirtualHost>

</IfModule>

Customize the above configuration for your own needs as this is not suitable for production environment.

Step 4. Starting httpd at boot up
We need the httpd to be up and running when the machines boots up. To achieve this we have to expose httpd as a service through init scripts.

The below script can be used to start and stop httpd at boot up.

#!/bin/sh

# chkconfig: - 64 36

# description: Apache Start|Restart|Stop Web Server

APACHE_HOME=/opt/jboss/httpd

case "$1" in

start)

echo "Starting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl start

;;

stop)

echo "Stopping Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl stop

;;

graceful)

echo "Restarting Apache gracefully..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl graceful

;;

restart)

echo "Restarting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl restart

;;

*)

echo "Usage: '$0' {start|stop|restart|graceful}" >&2

exit 64

;;

esac

exit 0

Copy the above script to /etc/init.d/httpd file or write your own startup script for apache httpd.

Give the file execute permission

chmod +x /etc/init.d/httpd

Add httpd as service at required run levels

chkconf -add httpd

chkconfig -level 345 httpd on

Now to test the set up try

service httpd start

Starting httpd:                                         [ OK ]

Try http://[ip]:[mod_clusterport]/mod_cluster_manager in the browser.

You should be able to see the following window

Step 5. Convert virtual machine to template
To avoid repeating the same steps for creating httpd virtual machine, you can create the clone of the vm. For vmware powerOff the virtual machine and clone it to template

Now we will look into how to create the jboss image.

Creating JBoss image
Step 1. Create the Centos vm

Refer image creation for httpd

Step 2. Install Java
You can get the latest Java from the following location and the second link explains steps for java installation.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

http://www.oracle.com/technetwork/java/javase/index-137561.html

Step 3. Installing JBoss AS with mod_cluster

We are using JBoss 5.1GA which can be obtained here. Let $JBOSS_HOME is the JBoss installation directory. For installing jBoss AS simply extract the downloaded tar file.

For the demo JBOSS_HOME = /home /JBoss-5.1.0.GA

Download the latest java bundles for mod_cluster here. mod_cluster 1.1.0 work with with JBoss AS 5.1 with out of box.Extract the mod_cluster-1.1.0.xxx-bin.tar.gz file and copy the mod_cluster.sar to the deploy folder.

tar xvf mod_cluster-1.1.0.CR3-bin.tar.gz

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Assuming you have extracted to /tmp directory

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Step 4. Configuration

The main configuration file is mod_cluster-JBoss-beans.xml under

$JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

By default mod_cluster is configured to work in clustered mode. In clustered mode, a single JBoss node is responsible for providing the entire cluster view to the front-end httpd processes.  The default configuration uses advertise mechanism using the mod_advertise module.

Step 5. JBoss as a service at startup

Execute the following commands to add new user jboss and give the startup file execute permission.

#create and give permissions to user jboss

adduser jboss

chown -Rf jboss.jboss /$JBOSS_HOME

#copy the default startup script to /etc/init.d

cd /$JBOSS_HOME /bin

cp JBoss_init_redhat.sh /etc/init.d/jboss

chmod +x /etc/init.d/jboss

Modify the /etc/init.d/jboss file to point JBOSS_HOME and JAVAPTH to point to the actual installed directories.

# chkconfig: - 35 90

# description: JBoss Start|Restart|Stop Application Server

# pidfile: /var/run/JBoss.pid

....

JBOSS_HOME=${JBOSS_HOME:-"$JBOSS_HOME"}

#define the user under which JBoss will run, or use 'RUNASIS' to run as the current user

JBOSS_USER=${JBOSS_USER:-"JBoss"}

#make sure java is in your path

JAVAPTH=${JAVAPTH:-"jdk installation folder "}

#configuration to use, usually one of 'minimal', 'default', 'all'

JBOSS_CONF=${JBOSS_CONF:-"all"}

#if JBOSS_HOST specified, use -b to bind JBoss services to that address

OS=`uname`

IP="" # store IP

case $OS in

Linux) IP=`ifconfig eth0| grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;

FreeBSD|OpenBSD) IP=`ifconfig eth0 | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;

SunOS) IP=`ifconfig -a eth0 | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;

*) IP="Unknown";;

Esac

#Bind to the current ip address

JBOSS_HOST=$IP

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

The above modification is to bind jboss to the ip address of the jboss instance.

To add jboss as a service at startup,

#command to start jboss at runlevel 3,4 and 5

chkconfig --add jboss

chkconfig --level 345 jboss on

service jboss start

Check in the browser if JBoss is started

http://[jboss-ip]:8080

Step 6. Convert vm to template

For vmware powerOff the virtual machine and clone it to template.

Testing the environment
Create virtual machines from the above created templates using vijava api or vCenter client. After one instance of both apache httpd and jboss got powered on, check the mod_cluster_manager using the url,

http://[webserverip]:[mod_clusterport]/mod_cluster_manager/

We can see that the JBoss worker is balanced by the mod_cluster. If we create one more JBoss instance, the new one will get added to that balancer. So if you have an application deployed on both of the JBoss instances, the requests will be distributed across the JBoss instances. Similarly when you start up new JBoss instances, the instances will get registered automatically to the proxy and become available for load balancing.If we kill a JBoss instance that will automatically get de-registered from the proxy balancer.

Set up in an environment where multicast is not supported
The above setup showed mod_cluster configuration using advertise mechanism, which uses muticast pings for auto discovery. But major cloud providers like Amazon EC2, Rackspace, GoGrid etc doesn't support multicast in their environment. To overcome this, information about the proxies can be passed through an JBoss argument (JBoss.mod_cluster.proxyList) at start instance up or use the addProxy method exposed by mod_cluster through JMX. The addProxy method takes the IP of httpd proxy and the port on which mod_cluster is listening. You can go to the JBoss AS JMX-Console to do this or use the java code to invoke this method remotely.

To disable the advertise mechanism following configuration changes need to be done :

At httpd side : Set the ServerAdvertise property to off in httpd.conf config file in /opt/JBoss/httpd/httpd/conf

ServerAdvertise off

At JBoss Side : Set advertise property in ModClusterConfig bean to false in mod_cluster-JBoss-beans.xml under $JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

<property name="advertise">false</property>

After setting these properties, create virtual machines from the templates. We can see in the mod_cluster_manger of the apache instance that that jboss node is not added. Now  we have to add the proxy instance to the jboss mod_cluster configuration through JMX. The following code snippet can be used to add a proxy to the balancer.

Hashtable contextProps = new Hashtable();

contextProps.put("java.naming.factory.initial"," org.JBoss.naming.HttpNamingContextFactory");

contextProps.put("java.naming.provider.url", http://+JBossinstanceip+":8080/invoker/JNDIFactory");

contextProps.put("java.naming.factory.url.pkgs", "org.JBoss.naming.client");

InitialContext ctx = new InitialContext(contextProps);  // From table

MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");

Object op = server.invoke(new ObjectName("JBoss.web:service=ModCluster"), "addProxy", new Object[]{webServerIP,webServermod_clusterPort},new String[]{"java.lang.String","int"} );

Now if you check the mod_cluster_manager we can see that the jboss node now balanced by mod_cluster.

Conclusion
With capabilities like dynamic addition of workers without any configuration changes, knowledge of deployed applications and calculation of the real time load balancing factor based on different metrics , it is certain that mod_cluster is the future of load balancer modules for apache and it will also have a huge impact in the cloud environment.

More Stories By Joel Mathew

Joel Mathew works as a Technology Analyst at SETLabs, R&D division, at Infosys Technologies Ltd. He has close to 3 years of experience in development of Cloud computing, Java and Java EE applications, Web 2.0,etc.

@ThingsExpo Stories
"There is a natural synchronization between the business models, the IoT is there to support ,” explained Brendan O'Brien, Co-founder and Chief Architect of Aria Systems, in this SYS-CON.tv interview at the 15th International Cloud Expo®, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...
The definition of IoT is not new, in fact it’s been around for over a decade. What has changed is the public's awareness that the technology we use on a daily basis has caught up on the vision of an always on, always connected world. If you look into the details of what comprises the IoT, you’ll see that it includes everything from cloud computing, Big Data analytics, “Things,” Web communication, applications, network, storage, etc. It is essentially including everything connected online from hardware to software, or as we like to say, it’s an Internet of many different things. The difference ...

ARMONK, N.Y., Nov. 20, 2014 /PRNewswire/ --  IBM (NYSE: IBM) today announced that it is bringing a greater level of control, security and flexibility to cloud-based application development and delivery with a single-tenant version of Bluemix, IBM's platform-as-a-service. The new platform enables developers to build ap...

Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world.
An entirely new security model is needed for the Internet of Things, or is it? Can we save some old and tested controls for this new and different environment? In his session at @ThingsExpo, New York's at the Javits Center, Davi Ottenheimer, EMC Senior Director of Trust, reviewed hands-on lessons with IoT devices and reveal a new risk balance you might not expect. Davi Ottenheimer, EMC Senior Director of Trust, has more than nineteen years' experience managing global security operations and assessments, including a decade of leading incident response and digital forensics. He is co-author of t...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Architect for the Internet of Things and Intelligent Systems at Red Hat, described how to revolutioniz...
Technology is enabling a new approach to collecting and using data. This approach, commonly referred to as the "Internet of Things" (IoT), enables businesses to use real-time data from all sorts of things including machines, devices and sensors to make better decisions, improve customer service, and lower the risk in the creation of new revenue opportunities. In his General Session at Internet of @ThingsExpo, Dave Wagstaff, Vice President and Chief Architect at BSQUARE Corporation, discuss the real benefits to focus on, how to understand the requirements of a successful solution, the flow of ...
The security devil is always in the details of the attack: the ones you've endured, the ones you prepare yourself to fend off, and the ones that, you fear, will catch you completely unaware and defenseless. The Internet of Things (IoT) is nothing if not an endless proliferation of details. It's the vision of a world in which continuous Internet connectivity and addressability is embedded into a growing range of human artifacts, into the natural world, and even into our smartphones, appliances, and physical persons. In the IoT vision, every new "thing" - sensor, actuator, data source, data con...
"BSQUARE is in the business of selling software solutions for smart connected devices. It's obvious that IoT has moved from being a technology to being a fundamental part of business, and in the last 18 months people have said let's figure out how to do it and let's put some focus on it, " explained Dave Wagstaff, VP & Chief Architect, at BSQUARE Corporation, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Focused on this fast-growing market’s needs, Vitesse Semiconductor Corporation (Nasdaq: VTSS), a leading provider of IC solutions to advance "Ethernet Everywhere" in Carrier, Enterprise and Internet of Things (IoT) networks, introduced its IStaX™ software (VSC6815SDK), a robust protocol stack to simplify deployment and management of Industrial-IoT network applications such as Industrial Ethernet switching, surveillance, video distribution, LCD signage, intelligent sensors, and metering equipment. Leveraging technologies proven in the Carrier and Enterprise markets, IStaX is designed to work ac...
C-Labs LLC, a leading provider of remote and mobile access for the Internet of Things (IoT), announced the appointment of John Traynor to the position of chief operating officer. Previously a strategic advisor to the firm, Mr. Traynor will now oversee sales, marketing, finance, and operations. Mr. Traynor is based out of the C-Labs office in Redmond, Washington. He reports to Chris Muench, Chief Executive Officer. Mr. Traynor brings valuable business leadership and technology industry expertise to C-Labs. With over 30 years' experience in the high-tech sector, John Traynor has held numerous...
Bit6 today issued a challenge to the technology community implementing Web Real Time Communication (WebRTC). To leap beyond WebRTC’s significant limitations and fully leverage its underlying value to accelerate innovation, application developers need to consider the entire communications ecosystem.
The 3rd International @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that it is now accepting Keynote Proposals. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades.
The Internet of Things is not new. Historically, smart businesses have used its basic concept of leveraging data to drive better decision making and have capitalized on those insights to realize additional revenue opportunities. So, what has changed to make the Internet of Things one of the hottest topics in tech? In his session at @ThingsExpo, Chris Gray, Director, Embedded and Internet of Things, discussed the underlying factors that are driving the economics of intelligent systems. Discover how hardware commoditization, the ubiquitous nature of connectivity, and the emergence of Big Data a...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
IoT is still a vague buzzword for many people. In his session at @ThingsExpo, Mike Kavis, Vice President & Principal Cloud Architect at Cloud Technology Partners, discussed the business value of IoT that goes far beyond the general public's perception that IoT is all about wearables and home consumer services. He also discussed how IoT is perceived by investors and how venture capitalist access this space. Other topics discussed were barriers to success, what is new, what is old, and what the future may hold. Mike Kavis is Vice President & Principal Cloud Architect at Cloud Technology Pa...
Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world. The next @ThingsExpo will take place November 4-6, 2014, at the Santa Clara Convention Center, in Santa Clara, California. Since its launch in 2008, Cloud Expo TV commercials have been aired and CNBC, Fox News Network, and Bloomberg TV. Please enjoy our 2014 commercial.