<?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>BoPL &#187; Recommended</title>
	<atom:link href="http://bopl.samharris.us/tag/recommended/feed/" rel="self" type="application/rss+xml" />
	<link>http://bopl.samharris.us</link>
	<description>It's not all caviar and baby wipes, mate</description>
	<lastBuildDate>Fri, 04 Feb 2011 08:35:52 +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 Tomcat on Leopard with mod_jk</title>
		<link>http://bopl.samharris.us/2008/05/load-balancing-tomcat-on-leopard-with-mod_jk/</link>
		<comments>http://bopl.samharris.us/2008/05/load-balancing-tomcat-on-leopard-with-mod_jk/#comments</comments>
		<pubDate>Wed, 28 May 2008 14:24:15 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Recommended]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://bopl.samharris.us/?p=967</guid>
		<description><![CDATA[I&#8217;ve just had to setup a test system that load balances a site running on Tomcat across multiple computers. My test bed is 3 mac minis, one working as the &#8216;head&#8217; running Apache, and the other two in the &#8216;farm&#8217; handling the load. It was a less than painless exercise, so I thought I&#8217;d write [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just had to setup a test system that load balances a site running on Tomcat across multiple computers.  My test bed is 3 mac minis, one working as the &#8216;head&#8217; running Apache, and the other two in the &#8216;farm&#8217; handling the load.  It was a less than painless exercise, so I thought I&#8217;d write up the instructions.</p>
<p><strong>1. Install Tomcat</strong><br />
Download Tomcat from <a href="http://tomcat.apache.org/download-60.cgi">here</a>.<br />
On each farm machine rename the folder to be Tomcat, then move it to the /Library/ directory.<br />
In Terminal:</p>
<p><code>cd /Library/Tomcat/bin<br />
rm *.bat<br />
rm *.exe<br />
chmod +x *</code></p>
<p>(You don&#8217;t need .bat or .exe files, but you do need other files to be executable).</p>
<p>Edit the file <code>/Library/Tomcat/conf/tomcat-users.xml</code> so that it reads:</p>
<p><code>
<pre>
&lt;?xml version=&#x27;1.0&#x27; encoding=&#x27;utf-8&#x27;?&gt;
&lt;tomcat-users&gt;
  &lt;role rolename=&quot;manager&quot;/&gt;
  &lt;user username=&quot;tomcat&quot; password=&quot;s3cret&quot; roles=&quot;manager&quot;/&gt;
&lt;/tomcat-users&gt;
</pre>
<p></code></p>
<p>(Note that the username and password are examples from Tomcat &#8211; you should probably change them).</p>
<p>Repeat the above for each farm machine.</p>
<p><strong>2. Deploy your application</strong><br />
Open each of your farm machines in turn from your browser, e.g.</p>
<p><code>http://farm1:8080/</code></p>
<p>You should see a screen that looks something like this:</p>
<div align=center>
<img src="http://bopl.samharris.us/wp/wp-content/uploads/2008/05/tomcat.png" alt="Welcome screen for a Tomcat installation" title="Tomcat" width="500" height="343"/></div>
<p>Click <em>Tomcat Manager</em> and enter the username and password you defined above.  This should show the <em>Tomcat Web Application Manager</em> screen.</p>
<p>Upload the war file of the application you want to run.  Once complete you should see a link on the manager page to your application.  Click it and make sure it works OK.</p>
<p>Repeat the above for each farm machine.</p>
<p><strong>3. Install mod_jk</strong><br />
Here&#8217;s the tricky bit.  Mod_jk is the apache module that handles the load balancing.  It&#8217;s available <a href="http://tomcat.apache.org/connectors-doc/">here</a>, BUT none of the downloads there will work on Leopard.  Apache on Leopard runs as 64 bit, which isn&#8217;t an option you can download from the Tomcat site.  So you have two options:</p>
<ul>
<li>Download the source code and build your own version.  This isn&#8217;t too hard if you have the relevant tools already installed &#8211; look <a href="http://blog.lo-fi.net/2007/10/leopard-for-web-developer-installing.html">here</a> for an excellent step-by-step on the changes you need to make to build a 64 bit version.</li>
<li>Use <a href="http://www.macports.org/">MacPorts</a></li>
<p>, which appears to have the facility to create a 64 bit version (I haven&#8217;t tested this).</p>
<li>Download the 64 bit version of <a href='http://bopl.samharris.us/wp/wp-content/uploads/2008/05/mod_jk.so'>mod_jk</a> 1.2.26 that I created.  I may update this as I go along, but no guarantees!</li>
</ul>
<p>Once you have your <code>mod_jk.so</code> file (if it doesn&#8217;t end up with that name, change the name) copy it to the <code>/usr/libexec/apache2/</code> directory of your head machine.  It&#8217;s worth changing the ownership and permissions of the file to match the other modules using the commands <code>sudo chown root:wheel mod_jk.so</code> and <code>sudo chmod 755 mod_jk.so</code>.</p>
<p><strong>4. Configure Apache</strong><br />
Edit the file <code>/etc/apache2/httpd.conf</code> and add the following lines:<br />
<code>
<pre>
#Added for Load Balancing
LoadModule jk_module libexec/apache2/mod_jk.so
# Path to workers.properties
JkWorkersFile /etc/apache2/workers.properties 

# Path to jk logs
JkLogFile /your-chosen-location/mod_jk.log

# Jk log level [debug/error/info]
JkLogLevel info

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

# JkOptions for forwarding
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

JkMount /your-application balancer
JkMount /your-application/* balancer
#End Added for Load Balancing
</pre>
<p></code></p>
<p>Note that you&#8217;ll need to set the location for your log file, and the name of your application.  It&#8217;s a good idea to create the log file (e.g. use <code>touch mod_jk.log</code> in the directory you want it; this makes sure the file can be created, which would otherwise trip Tomcat up.</p>
<p>Now create a new file <code>worker.properties</code> in <code>/etc/apache2</code> containing the following:</p>
<p><code>
<pre>workers.tomcat_home=/Library/Tomcat
workers.java_home=/System/Library/Frameworks/JavaVM.framework/Versions/Current

worker.list=balancer
worker.maintain=5

worker.farm1.port=8009
worker.farm1.host=farm1-IP-address
worker.farm1.type=ajp13
worker.farm1.lbfactor=1

worker.farm2.port=8009
worker.farm2.host=farm2-IP-address
worker.farm2.type=ajp13
worker.farm2.lbfactor=10

worker.balancer.type=lb
worker.balancer.balance_workers=farm1,farm2
worker.balancer.method=Request</pre>
<p></code></p>
<p>The <code>worker.maintain</code> setting helps determine how long one farm machine will be used before the load switches to another machine.  For testing I used 5 (seconds); the default is 60.</p>
<p><strong>5. Start Apache</strong><br />
Tomcat should still be running on each of the farm servers, so start Apache on your head machine by opening System Preferences&#8230;Sharing and checking the &#8216;Web Sharing&#8217; box (if it was already checked then uncheck and recheck it to restart Apache).</p>
<p><strong>6. Test it out</strong><br />
Browse to <code>http://head/your-application</code> &#8211; you should see your application!</p>
<p><strong>Credits</strong><br />
This post was based on the excellent work found <a href="http://thought-bytes.blogspot.com/2007/03/how-to-load-balance-tomcat-55-with.html">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bopl.samharris.us/2008/05/load-balancing-tomcat-on-leopard-with-mod_jk/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

