<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DirkReske.de &#187; apache</title>
	<atom:link href="http://www.dirkreske.de/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dirkreske.de</link>
	<description>Personal homepage of Dirk Reske</description>
	<lastBuildDate>Fri, 07 Oct 2011 13:29:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Load balancing glassfish using apache</title>
		<link>http://www.dirkreske.de/load-balancing-glassfish-using-apache/</link>
		<comments>http://www.dirkreske.de/load-balancing-glassfish-using-apache/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 23:19:48 +0000</pubDate>
		<dc:creator>Dirk Reske</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[high availability]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[load balancing]]></category>

		<guid isPermaLink="false">http://www.dirkreske.de/?p=116</guid>
		<description><![CDATA[Overview After my articles about setting up a glassfish cluster and enable session replication, its now time to put a load balancer in front of it. A couple of times I&#8217;ve tried to get the Sun load balancing plugin working, but without success. This was because of  some operating system issues or other problems. So &#8230; </p><p><a class="more-link block-button" href="http://www.dirkreske.de/load-balancing-glassfish-using-apache/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<h3>Overview</h3>
<p>After my articles about <a href="http://www.dirkreske.de/glassfish-cluster-configuration/">setting up a glassfish cluster</a> and <a href="http://www.dirkreske.de/enable-glassfish-session-replication/">enable session replication</a>, its now time to put a load balancer in front of it.</p>
<p>A couple of times I&#8217;ve tried to get the Sun load balancing plugin working, but without success. This was because of  some operating system issues or other problems.<br />
So after looking around the web, I&#8217;ve found some good solutions using apache and the mod_jk connector from the apache tomcat project.</p>
<h3>Requirements</h3>
<ul>
<li>Recent glassfish installation (I use v2.1.1).</li>
<li><a href="http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html" target="_blank">mod_jk</a> tomcat connector.</li>
<li><a href="http://tomcat.apache.org/" target="_blank">Apache tomcat</a> server to get some files from (Use version 5.5.23, others won&#8217;t work).</li>
<li><a href="http://commons.apache.org/logging/" target="_blank">Apache commons logging</a></li>
<li><a href="http://commons.apache.org/modeler/" target="_blank">Apache commons modeler</a></li>
</ul>
<h3>Installation</h3>
<ol>
<li>Configuring the glassfish cluster
<ol>
<li>Copy the <em>$CATALINA_HOME/server/lib/tomcat-ajp.jar</em> to your <em>$GLASSFISH_HOME/lib </em>directory on each glassfish installation in your cluster.</li>
<li>Also copy the<em> commons-logging.jar</em> and<em> commons-modeler.jar</em> to your <em>$GLASSFISH_HOME/lib </em>directory on each glassfish installation in your cluster.</li>
<li>Now you have to define <em>jvmRoute </em>and<em> com.sun.enterprise.web.connector.enableJK</em> system properties for the cluster (this can be done from the domain administration server)
<pre>asadmin create-jvm-options --target cluster1 "-DjvmRoute=\${AJP_INSTANCE_NAME}"
asadmin create-jvm-options --target cluster1 "-Dcom.sun.enterprise.web.connector.enableJK=\${AJP_PORT}"</pre>
</li>
<li>Now you have to define the values for these properties for each instance running in the cluster (this can also be done from the domain administration server)
<pre>asadmin create-system-properties --target instance1 AJP_INSTANCE_NAME=instance1
asadmin create-system-properties --target instance1 AJP_PORT=8020</pre>
</li>
</ol>
</li>
<li>Configuring the apache web server
<ol>
<li>Copy the mod_jk.so to a apache accessible directory.</li>
<li>Copy the following lines to your apache main config file.
<pre>LoadModule jk_module <strong>&lt;path to your mod_jk.so&gt;</strong>
JkWorkersFile <strong>&lt;path to your worker.properties (created later)&gt;</strong>
JkLogFile <strong>&lt;path to your mod_jk.log&gt;</strong>
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"</pre>
</li>
<li>Copy the following lines to your virtual host configuration (or into the main config, if you don&#8217;t use virtual hosts).
<pre>JkMount /* loadbalancer</pre>
</li>
<li>This will redirect all requests to your load balancer. (You can also use patterns like <em>/*.jsp</em> for only redirecting jsp file request to the load balancer or just any other sensefull pattern).</li>
</ol>
</li>
<li>Writing your worker.properties configuration file.
<pre>worker.list=loadbalancer

# Set properties for instance1
worker.instance1.type=ajp13
worker.instance1.host=<strong>&lt;host of instance1&gt;</strong>
worker.instance1.port=<strong>&lt;AJP port of instance1&gt;</strong>
worker.instance1.lbfactor=50
worker.instance1.connection_pool_size=10
worker.instance1.connection_pool_timeout=600
worker.instance1.socket_keepalive=1
worker.instance1.socket_timeout=300

# Set properties for instance2
worker.instance2.type=ajp13
worker.instance2.host=<strong>&lt;host of instance2&gt;</strong>
worker.instance2.port=<strong>&lt;AJP port of instance2&gt;</strong>
worker.instance2.lbfactor=50
worker.instance2.connection_pool_size=10
worker.instance2.connection_pool_timeout=600
worker.instance2.socket_keepalive=1
worker.instance2.socket_timeout=300

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=instance1,instance2</pre>
</li>
<li>Restart all cluster instances and the web server. Your load balancing should be working now.<br />
Each time a new session is creted by the glassfish, it appends its instance name to the JSESSIONID, so the load balancer can determine on which instance to route the request.<br />
If one instance crashes, the load balancer will notice this and redirects all requests to another instance. If you have enabled session replication, your old session will be resumed there.</li>
</ol>
<h3>Further reading</h3>
<ul>
<li><a href="http://www.dirkreske.de/enable-glassfish-session-replication/">enable session replication</a></li>
<li><a href="http://www.dirkreske.de/glassfish-cluster-configuration/">setting up a glassfish cluster</a></li>
<li><a href="http://tomcat.apache.org/connectors-doc/reference/workers.html" target="_blank">mod_jk connector documentation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dirkreske.de/load-balancing-glassfish-using-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

