原文地址:
http://aofengblog.blog.163.com/blog/static/631702120093175474528/
1、安装Tomcat,具体的过程不再详述。如有需要,可以参考我的另一篇文章: Tomcat - 在Linux上安装 。
apr下载地址:apr.apache.org
2、编译安装APR。
解压文件
tar zxvd apr-1.3.3.tar.gz
安装三步曲
./configure --prefix=/opt/project/tomcat/apr
make
make install
3、编译安装APR UTIL。
解压文件
tar zxvd apr-util-1.3.4.tar.gz
安装三步曲
./configure --prefix=/opt/project/tomcat/apr --with-apr=/opt/project/tomcat/apr
make
make install
4、编译安装Native。
解压文件
tar zxvd tomcat-native-1.1.16-src.tar.gz
安装三步曲
cd jni/native
./configure --with-apr=/opt/project/tomcat/apr/bin/apr-1-config \
--with-java-home=$JAVA_HOME \
--with-ssl=yes \
--prefix=$CATALINA_HOME
make
make install
5、修改Tomcat的启动参数。
打到Tomcat安装目录下 bin/catalina.sh 文件,找到如下内容:
# Get standard environment variables
在其下面添加一行:
JAVA_OPTS="-Djava.library.path=/opt/project/tomcat/lib"
或 JAVA_OPTS="-Djava.library.path=/opt/project/tomcat/apr/lib" ?(这个没成功)
6、验证。
进入Tomcat的bin目录,执行:
aofeng@linux:~/apache-tomcat-5.5.27/bin> ./startup.sh
Using CATALINA_BASE: /data/aofeng/apache-tomcat-5.5.27
Using CATALINA_HOME: /data/aofeng/apache-tomcat-5.5.27
Using CATALINA_TMPDIR: /data/aofeng/apache-tomcat-5.5.27/temp
Using JRE_HOME: /data/aofeng/jdk1.5.0_16/jre
进入Tomcat的logs目录,打开 catalina.out 文件,可以看到控制台输出的日志如下:
Aug 04, 2011 1:13:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.20.
Aug 04, 2011 1:13:50 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Aug 04, 2011 1:13:50 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Failed to initialize the SSLEngine.
Aug 04, 2011 1:13:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-80"]
Aug 04, 2011 1:13:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
Aug 04, 2011 1:13:50 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 673 ms
Aug 04, 2011 1:13:50 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 04, 2011 1:13:50 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.19
Aug 04, 2011 1:13:50 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
Aug 04, 2011 1:13:51 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already defined
Aug 04, 2011 1:13:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-apr-80"]
Aug 04, 2011 1:13:54 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Aug 04, 2011 1:13:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3693 ms
注意上面用红色标识的部分,说明APR应用成功。
如果还是报错路径下找不到库:
息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /home/saas/jdk1.6.0_13/jre/lib/amd64/server:/home/saas/jdk1.6.0_13/jre/lib/amd64:/home/saas/jdk1.6.0_13/jre/../lib/amd64:/usr/java/packages/lib/amd64:/lib:/usr/lib
解决,将安装好的libtcnative库拷贝到上面提示的任一地址下即可:
# ll ~/jdk1.6.0_13/jre/lib/amd64/server/
-rw-r--r-- 1 saas saas 1604882 6月 18 16:43 libtcnative-1.a
-rwxr-xr-x 1 saas saas 1042 6月 18 16:43 libtcnative-1.la
-rwxr-xr-x 1 saas saas 902937 6月 18 16:42 libtcnative-1.so
-rwxr-xr-x 1 saas saas 902937 6月 18 16:43 libtcnative-1.so.0
-rwxr-xr-x 1 saas saas 902937 6月 18 16:43 libtcnative-1.so.0.1.24