How to install and use Apache Tomcat Native in Debian Squeeze

The Apache Tomcat Native or tc-native is composed of JNI native wrappers to Apache Portable Runtime (APR).   According to the tc- native documentation, it provides performance benifits especially if Web Applications are using SSL or serve large amount of static data.

Tc-native do not have binary distribution for Debian or Linux for that matter.   You build from the sources that come with each Tomcat release.   It can be found as tarball ${CATALINA_HOME}/bin/tomcat-native.tar.gz.   Tc-native is also available as a separate download from the Tomcat Native website in the link that follows.   This is also the latest version.

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

Whichever copy you use,  you need the following components installed in your system to build tc-native.

  • APR library
  • OpenSSL libraries
  • Java SE Development Kit (JDK)

Install APR and OpenSSL

From this point on,  we assume you are logged in as root.   It is also assumed that you already have an existing Tomcat/Java installation.

apt-get update
apt-get install build-esential libapr1 libaprutil1 libapr1-dev libssl-dev

This will install APR, OpenSSL libraries and build tools.

Build tc-native

Copy the tarball ${CATALINA_HOME}/bin/tomcat-native.tar.gz or your downloaded copy (if this was preferred) to any desired location.   Say your desired location is /home/user/tmp

cd /home/user/tmp
cp ${CATALINA_HOME}/bin/tomcat-native.tar.gz . 
tar xvfz tomcat-native.tar.gz
cd jni/native
./configure --with-apr=/usr/bin/apr-1-config

(Note that if you used a downloaded copy,  "tomcat-native.tar.gz" should be the filename of the download and "${CATALINA_HOME}/bin/" is its location.)

The ./configure command will auto detect your JVM and SSL installations.   You could also explicitly enter the JAVA_HOME of the JVM you want to use, usefull if you have mulitple Java installations or "configure" detected a JVM that is not what you wanter to use.   Use following command format:

./configure --with-apr=/usr/bin/apr-1-config 
	    --with-java-home={YOUR_JAVA_HOME_USED_BY_TOMCAT} 

The output of this command is a Makefile configured to your system.

Then finally issue the following command:

make && make install

This will build and install tc-native (libtcnative) to /usr/local/apr/lib

There are two options you can do to make tc-native available to Tomcat.

Add tc-native libraries path to your LD_LIBRARY_PATH.   This can be done in ${CATALINA_HOME}/bin/setenv.sh.   Find LD_LIBRARY_PATH and change it to look like below:

 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
 export LD_LIBRARY_PATH

or

Create a symbolic /usr/lib/libtcnative-1.so that points to /usr/local/apr/lib/libtcnative-1.so.   Enter the following command:

ln -s /usr/local/apr/lib/libtcnative-1.so /usr/lib/libtcnative-1.so

Either method you used,  tc-native becomes available the next time you restart Tomcat.   Once Tomcat is restarted check your logs for the following to ensure that APR has been loaded:

INFO: Loaded APR based Apache Tomcat Native Library 1.1.24

The Tomcat connectors configuration

The default connector used by Tomcat is "HTTP/1.1".   According to the Tomcat documentation,  this is in a switching mode that switches between blocking Java connector and APR native (tc-native) when available.

You can also explicitly define/use an APR connector by editing your ${CATALINA_HOME}/conf/server.xml,  and change the protocol.

Before:

	<Connector port="8080" protocol="HTTP/1.1"
		connectionTimeout="20000"
		redirectPort="8443" />

Change it to the following:

	<Connector port="8080" 
		protocol="org.apache.coyote.http11.Http11AprProtocol"
		connectionTimeout="20000"
		redirectPort="8443" />

Save and restart Tomcat.

That's it. Good luck.

If you like the article, please share.
(Site URL pattern has changed as a result social actions counter was reset.)



Comment icon   Comments (Newest first)