欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux下Springboot解决`APR based Apache Tomcat Native library`提示

程序员文章站 2022-03-17 13:57:21
最近转行做 ,开发基于 的项目,版本号为 . 启动应用,发现以下提示: 提示告知,使用基于 的`ARP 性能`. 以下是从网上节选的话语: apr是从操作系统级别解决 问题,大幅度提高服务器的 ,也是Tomcat生产环境运行的首选方式. 目前Tomcat 8.x默认情况下全部是运行在 模式下,而ap ......

最近转行做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 libraryarp可以提升生产环境性能.
以下是从网上节选的话语:

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,性能就等着提升了.
将参数设置到ideavm options中,调试的时候也舒服了许多.

ps:
如果您觉得我的文章对您有帮助,可以扫码领取下红包,谢谢!
Linux下Springboot解决`APR based Apache Tomcat Native library`提示