Linux下Springboot解决`APR based Apache Tomcat Native library`提示
最近转行做java
,开发基于Springboot
的项目,版本号为2.1.0.RELEASE
.
启动应用,发现以下提示:
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
提示告知,使用基于Apache Tomcat Native library
的ARP
可以提升生产环境性能
.
以下是从网上节选的话语:
apr是从操作系统级别解决
异步IO
问题,大幅度提高服务器的并发处理性能
,也是Tomcat生产环境运行的首选方式.
目前Tomcat 8.x默认情况下全部是运行在nio
模式下,而apr的本质就是使用jni技术调用操作系统底层的IO接口.
如此具有诱惑力,当然值得花费时间去解决,按照网上教程安装依赖:
sudo apt-get isntall libapr1-dev libssl-dev libtcnative-1
此处,需要注意网上给出的资源大多数是libapr
以及libtcnative
,安装时提示无法找到.
因此,搜索到包名被修改成上述定义.
$ dpkg -L libtcnative-1
# 以下是输出信息
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libtcnative-1.a
/usr/lib/x86_64-linux-gnu/libtcnative-1.so.0.2.16
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/tcnative-1.pc
/usr/share
/usr/share/doc
/usr/share/doc/libtcnative-1
/usr/share/doc/libtcnative-1/README.Debian
/usr/share/doc/libtcnative-1/changelog.Debian.gz
/usr/share/doc/libtcnative-1/changelog.gz
/usr/share/doc/libtcnative-1/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libtcnative-1
/usr/lib/x86_64-linux-gnu/libtcnative-1.so
/usr/lib/x86_64-linux-gnu/libtcnative-1.so.0
使用dpkg
可以得知,libtcnative-1
的静态库被安装至:/usr/lib/x86_64-linux-gnu
.
因此,启动程序:
java -jar -Djava.library.path=/usr/lib/x86_64-linux-gnu cache-0.0.1-SNAPSHOT.jar
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2019-01-10 15:33:55.586 INFO 2243 --- [ main] o.a.catalina.core.AprLifecycleListener : An older version [1.2.16] of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.18]
2019-01-10 15:33:55.586 INFO 2243 --- [ main] o.a.catalina.core.AprLifecycleListener : Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
2019-01-10 15:33:55.586 INFO 2243 --- [ main] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2019-01-10 15:33:55.586 INFO 2243 --- [ main] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2019-01-10 15:33:55.597 INFO 2243 --- [ main] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.0h 27 Mar 2018]
2019-01-10 15:33:55.748 INFO 2243 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
输出的启动信息中,可以看到APR based Apache Tomcat Native library
被加载了.
但是让人心塞的是,输出信息中提示版本过低,不满足现阶段使用的最小版本要求(差了两个小版本号).
An older version [1.2.16] of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.18]
根据网上搜索结果可知,无法通过apt-get
去安装高版本的libtcnative
,只能手动编译安装.
因此,去Tomcat
官网下载(http://tomcat.apache.org/native-doc/
),可以看到最新的版本号为1.2.19
,于是下载源码包.
解压后可以看到目录结构:
.
├── build.properties.default
├── build.xml
├── CHANGELOG.txt
├── CMakeLists.txt
├── docs
├── examples
├── java
├── jnirelease.sh
├── LICENSE
├── native
├── NOTICE
├── README.txt
├── test
├── TODO.txt
└── xdocs
执行以下命令,进行编译安装:
sudo apt-get autoremove libtcnative-1 #删除安装的库
cd native
./configure && make -j 4
sudo make install
此处,configure
命令无需按照官网指示配置参数,会自行搜索依赖所在路径.
安装完之后,可以得知静态库被安装至/usr/local/apr/lib
.
重新启动程序:
java -jar -Djava.library.path=/usr/local/apr/lib cache-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
o.a.catalina.core.AprLifecycleListener : Loaded APR based Apache Tomcat Native library [1.2.19] using APR version [1.6.3].
2019-01-10 15:48:29.130 INFO 7538 --- [ main] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2019-01-10 15:48:29.130 INFO 7538 --- [ main] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2019-01-10 15:48:29.136 INFO 7538 --- [ main] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.0h 27 Mar 2018]
2019-01-10 15:48:29.255 INFO 7538 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
通过输出信息,可以得知:程序完美加载APR based Apache Tomcat Native library
,性能就等着提升了.
将参数设置到idea
的VM options
中,调试的时候也舒服了许多.
PS:
如果您觉得我的文章对您有帮助,可以扫码领取下红包,谢谢!