解决Tomcat的APR(Apache Portable Runtime)的安装和配置问题

我在主机上安装了Tomcat,主机操作系统是RedHat Enterprise。在日志中发现以下信息:
Tomcat停止时出现的信息:

Failed shutdown of Apache Portable Runtime

Tomcat启动时出现的信息:
The Apache Tomcat Native library which allows optimal performance in production environments was not found

问题原因是没有安装APR,虽然只是INFO类日志,而且不知道APR到底有什么作用,还是以下面的步骤解决了这个问题。

安装APR

APR需要的工作环境:

  • APR library
  • JNI wrappers for APR used by Tomcat (libtcnative)
  • OpenSSL libraries
  • 当前OpenSSL已经安装好了,下面只需要安装前两项。



    APR的作用

    The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.

    真不知道在哪个地方使用这种不依赖于操作系统的运行环境,我用Tomcat运行用Java写的应用,Java本来就是跨操作系统的,好像APR对我用处不大,先不管这么多,安装好后在研究。



    下载和安装

    Apache网站上下载1.3.3 core源代码: apr-1.3.3-tar.gz,解开。

    依照[2],执行下面的操作:

    1. ./configure
    2. make
    3. make install(要用超级用户身份)

    apr库安装在/usr/local/apr下



    安装JNI wrapper库

    在Tomcat的程序包中,在bin目录下有bin/tomcat-native.tar.gz,解开,执行:

    1. cd tomcat-native-1.1.12-src/jni/native
    2. ./configure --with-apr=/usr/local/apr (通过执行 ./configure --help 发现了这个参数,即怎样指定APR的目录)
    3. make
    4. make install(需要超级用户身份)

    执行后,在/usr/local/apr/lib下创建各种tcnative函数库



    使用APR库

    在启动Tomcat时要告诉它到哪里找APR库,估计有很多方法,我采用的方法是:

    增加环境变量:

    CATALINA_OPTS=-Djava.library.path=/usr/local/apr/lib

    启动时发现日志中有:
    Sep 30, 2008 4:32:55 PM org.apache.coyote.http11.Http11AprProtocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Sep 30, 2008 4:32:55 PM org.apache.coyote.ajp.AjpAprProtocol start
    INFO: Starting Coyote AJP/1.3 on ajp-8009

    停止时发现日志中有:
    Sep 30, 2008 4:27:06 PM org.apache.coyote.http11.Http11AprProtocol destroy
    INFO: Stopping Coyote HTTP/1.1 on http-8080
    Sep 30, 2008 4:27:06 PM org.apache.coyote.ajp.AjpAprProtocol destroy
    INFO: Stopping Coyote AJP/1.3 on ajp-8009

    APR安装成功。

好像APR提供更高级的IO

可能IO的性能会大大提高,参见下面的材料:

sorry, just a test :)

sorry, just a test :)