Friday, January 4, 2013

Configure MacOSX - Mountain Lion - to install/use Jk module in Apache installation to connect to Tomcat servlet container or webserver


Configure MacOSX - Mountain Lion - to use Jk module in Apache installation to connect to Tomcat servlet container or webserver

The following set of steps need to be configured to install/invoke the jk module(mod_jk.so) for loadbalancing requests to different server nodes - Tomcat/Jboss servlet -

1.Apache server comes pre-installed in mac-osx, I am using 'Mountain Lion', you can refer to the copy installed in your server.
 The installation sits as follows -
 executables - /etc/apache2
 libraries - /usr/libexec/apache2
 logs - /var/log/

 Download the latest jk module version from apache site -

 http://tomcat.apache.org/download-connectors.cgi

 I am using - tomcat-connectors-1-1.2.37-src.tar.

2.Decompress the downloaded file -

$ cd <Downloaded directory>
$ tar -xvf <Downloaded directory>/tomcat-connectors-1-1.2.37-src.tar

3.You need Xcode to make , compile and configure the apache module. To configure the make file the Apache Extension Tool apxs is used.

 - Download the Xcode from 'Mac App Store', its free to download.
 - Install the Xcode.
 - Go to Xcode -> Preferences and download the install the 'Command Line Tools'.

4.Run the compilation procedure for apache modules -
- $ cd tomcat-connectors-1.2.30-src/native
- $ ./configure --with-apxs=/usr/sbin/apxs

 Sometimes, if you are installing the Xcode after using your OS for some time you might have an OS specific XToolchain reference -

In such case you will get an error on compiling - view the 'config.log' for more details.
The error would point to missing path reference -

eg: configure:5139: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc --version >&5

Here the 'OSX10.8.xctoolchain' would not exist - instead the path would be like -

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

You need to make a symlink for such a scenario -
$cd /Applications/Xcode.app/Contents/Developer/Toolchains
$sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain


5.Run the compile again. Refer to the below document link if you still face errors -
    http://stackoverflow.com/questions/10357804/configure-error-c-compiler-cannot-create-executables
   
6.Issue the following commands post successful execution
$ make clean
    $ make
    $ sudo make install

7. Configuration of 'jk' module. Post successful compilation and installation, the following configuration files need to be created for apache server to know how to load and use the jk module.
   These configurations reside in the 'other' directory.
 $ cd /etc/apache2/other
 $ sudo vi mod_jk.conf

LoadModule jk_module libexec/apache2/mod_jk.so
JkWorkersFile /etc/apache2/other/workers.properties
JkMountFile /etc/apache2/other//uriworkermap.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkMount /examples/* ajp13
JkMount /host-manager/* ajp13
JkMount /docs/* ajp13
JkMount /manager/* ajp13

In my configuration there is an additional file - 'uriworkermap.properties' to redirect all requests of specific pattern to loadbalancer profile in worker.properties.

The first three lines in file - load the mod_jk.so file, configure apache to use workers.properties as workers file and mount file uriworkermap.properties to resolve any uri before processing with workermap.
The rest of the lines are used to configure shared memory,logging & mount directories for projects.

8. Create workers.properties -

$sudo vi workers.properties
worker.list=loadbalancer,status

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1
worker.loadbalancer.sticky_session=1

worker.node1.port=8009
worker.node1.host=127.0.0.1
worker.node1.type=ajp13
worker.node1.connection_pool_timeout=600000

9. Configure the document root for any documents or staticcontent to point to your directory having static content -

The default configuration is '<Directory "/Library/WebServer/Documents">' in file --> /etc/apache2/httpd.conf.


10.Create a uriworkermap.properties

$sudo vi uriworkermap.properties
 /xyz|/*=loadbalancer
!/xyz/staticcontent|/*=loadbalancer

This uri configuration helps to redirect any requests for 'xyz' context to folder housing the 'loadbalancer' and folder housing 'staticcontent'.
This can be changed as per your needs.

 11.Stop and restart the apache server-
 $ sudo apachectl graceful-stop
 $ sudo apachectl start

11.The server should start without any issues. If it doesn't there is some problem with the configuration.

Issue the below urls to check server startup and content directory configuration -

http://localhost
http://localhost/PoweredByMacOSX.gif

'PoweredByMacOSX.gif' is generally present in '/Library/WebServer/Documents' directory.

No comments:

Post a Comment