CentOS: Installing Apache Portable Runtime (APR) for Tomcat
Introduction
In Tomcat, the default HTTP Connector is BIO (Blocking I/O) connector with stability, low concurrency characteristics. To boost the Tomcat performance, the alternative ways either adapt NIO (Non-Blocking I/O) or APR (Apache Portable Runtime) connector. Especially, the APR performance is generally better than others when using SSL protocol. For more details on performance among these connectors can reference the Mike Noordermeer’s comparison.
Prerequisites for installing APR
- APR library
- APR-util library
- OpenSSL library
To begin our installation, we’ll first need to install the OpenSSL to the server because we install CentOS 6.3 with minimal installation media:
# yum install openssl-devel
In addition, we’ll execute the configure
or make
commands in the next following steps, you may install the related tools if you cannot perform those commands as mentioned above:
# yum groupinstall "Development Tools"
Download and Install APR
# wget http://ftp.mirror.tw/pub/apache/apr/apr-1.4.8.tar.gz
# tar -zxvf apr-1.4.8.tar.gz
# cd apr-1.4.8
# ./configure
# make
# make install
The default installation path is /usr/local/apr
Download and Install APR-util
# wget http://ftp.mirror.tw/pub/apache/apr/apr-util-1.5.2.tar.gz
# tar -zxvf apr-util-1.5.2.tar.gz
# cd apr-util-1.5.2
# ./configure --with-apr=/usr/local/apr
# make
# make install
The default path of installation is /usr/local/apr/lib
Install JNI Wrapper for APR used by Tomcat (libtcnative)
# cd $CATALINA_HOME/bin
# tar -zxvf tomcat-native.tar.gz
# cd tomcat-native-1.1.27-src/jni/native
# ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.7.0_25
# make
# make install
The native libraries were installed in /usr/local/apr/lib
Integrate APR with Tomcat
There are two ways to set Tomcat integrate with APR. One is you can add the following parameter when start up the Tomcat in bin/catalina.sh
:
CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"
The other is to add a new environment variable LD_LIBRARY_PATH
in /etc/profile
:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
Then makes it effect via:
# source /etc/profile
After restarting the Tomcat service, we can get the following message in catalina.out
log if APR was installed successfully.
Sep 06, 2013 2:10:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.8.
Sep 06, 2013 2:10:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Tomcat SSLEngine Error
SEVERE: Failed to initialize the SSLEngine.
org.apache.tomcat.jni.Error: 70023: This function has not been implemented on this platform
at org.apache.tomcat.jni.SSL.initialize(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.core.AprLifecycleListener.initializeSSL(AprLifecycleListener.java:259)
at org.apache.catalina.core.AprLifecycleListener.lifecycleEvent(AprLifecycleListener.java:110)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:99)
at org.apache.catalina.startup.Catalina.load(Catalina.java:640)
at org.apache.catalina.startup.Catalina.load(Catalina.java:665)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
If you got the SSLEngine error message and your site without SSL support, you can fix this error via turn this initialization off in conf/server.xml
.
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />