tomcat启动报错APR问题

 

背景

很多的生产环境项目都在使用tomcat,所以要经常的跟tomcat打交道,排错是家常便饭。本博文主要是是介绍关于tomcat启动时报APR错误,报错信息如下:

02-Aug-2017 18:13:00.769 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR 
based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: 
[/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]


apr官网简介

Tomcat可以使用APR来提供超强的可伸缩性和性能,更好地集成本地服务器技术。APR(Apache Portable Runtime)是一个高可移植库,它是Apache HTTP Server 2.x的核心。APR有很多用途,包括访问高级IO功能(例如sendfile,epoll和OpenSSL),OS级别功能(随机数生成,系统状态等等),本地进程管理(共享内存,NT管道和UNIX sockets)。

 

这些功能可以使Tomcat作为一个通常的前台WEB服务器,能更好地和其它本地web技术集成,总体上让Java更有效率作为一个高性能web服务器平台而不是简单作为后台容器。在产品环境中,特别是直接使用Tomcat做WEB服务器的时候,应该使用Tomcat Native来提高其性能。

 

概括起来就是如何在Tomcat中使用JNI的方式来读取文件以及进行网络传输。这个东西可以大大提升Tomcat对静态文件的处理性能,同时如果你使用了HTTPS方式 传输的话,也可以提升SSL的处理性能。

官网链接

http://tomcat.apache.org/tomcat-7.0-doc/apr.html

http://tomcat.apache.org/tomcat-8.5-doc/apr.html

 

环境说明

下面是以已经安装好JDK和tomcat为前提,我的环境如下

Centos7.3_x64

Tomcat8.5.16

Jdk1.8.0_131

 

安装

 本文中涉及的安装包打包下载地址:

http://down.51cto.com/data/2331074

一、windows下安装

直接拷贝tcnative-1.dll到TOMCAT_HOME/bin目录下,启动即可

下载地址: http://archive.apache.org/dist/tomcat/tomcat-connectors/native/

 

二 、linux下安装


2.1下载安装包

下载地址: http://apr.apache.org/

http://www.openssl.org/

apr-1.6.2.tar.gz

apr-iconv-1.2.1.tar.gz

apr-util-1.6.0.tar.gz

openssl-1.0.2l.tar.gz

 

2.2 安装apr插件

1)安装apr

tar zxvf apr-1.6.2.tar

cd apr-1.6.2

./configure --prefix=/usr/local/apr

make

make install

 

2)安装apr-iconv

程序代码

tar -zxvf apr-iconv-1.2.1.tar.gz

cd apr-iconv-1.2.1

./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr

make

make install

 

3)安装apr-util

tar zxvf apr-util-1.6.0.tar.gz

cd apr-util-1.6.0

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv

make

make install

 

4)安装tomcat-native

(此包tomcat自带,在bin目录下)

tar zxvf tomcat-native.tar.gz

cd tomcat-native-1.2.12-src/native

./configure --with-apr=/usr/local/apr --with-java-home= /usr/java/jdk1.8.0_131 --with-ssl=/usr/local/openssl

make

make install

备注:编译时报错openssl版本有问题,请参考问题汇总问题3

 

5)添加环境变量

vi /etc/profile #在他文件末尾处添加下面的变量

# apr

export LD_LIBRARY_PATH=/usr/local/apr/lib

立即生效

source /etc/profile

 

使用./catalina configtest检测问题,报错已经消失。

正常信息显示如下:

02-Aug-2017 18:17:13.908 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR 
based Apache Tomcat Native library [1.2.12] using APR version [1.6.2].

02-Aug-2017 18:17:13.908 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR 
capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].

02-Aug-2017 18:17:13.908 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL
 configuration: useAprConnector [false], useOpenSSL [true]

02-Aug-2017 18:17:13.922 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL 
successfully initialized [OpenSSL 1.0.2l 25 May 2017]

问题汇总

1.如果经过上述部署后,还是报错?

复制/usr/local/apr/lib/文件到/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib任何目录即可。

 

2.错误:SEVERE: Failed to initialize the SSLEngine?

SEVERE: Failed to initialize the SSLEngine.
org.apache.tomcat.jni.Error: 70023: This function has not been implemented on this platform

请关闭SSL侦听,除非你有使用SSL

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />

 

3.报错openssl版本有问题?

编译native时,报错openssl版本有问题,所以此时只能先解决openssl的问题。

出现错误:configure: error: Your version of OpenSSL is not compatible with this version of tcnative


tar zxf openssl-1.0.2l.tar.gz

./config –prefix=/usr/local/openssl –fPIC

#加上-fPIC参数,否则编译native的时候会报错,如附一

make

make install


附一:编译native报错

/usr/local/openssl/lib/libssl.a(s3_meth.o): relocation R_X86_64_32 
against `.rodata' can not be used when making a shared object; recompile
 with –fPIC
/usr/local/openssl/lib/libssl.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[1]: *** [libtcnative-1.la] Error 1
make[1]: Leaving directory `/usr/local/tomcat-native-1.2.8-src/native'
make: *** [all-recursive] Error
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章