背景
很多的生产环境项目都在使用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]
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
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