Debian下启用Tomcat APR运行模式
参考:https://tomcat.apache.org/tomcat-8.5-doc/apr.html
环境:
debian9
jdk8
tomcat8.5
APR运行模式是什么
APR从操作系统级别来解决异步的IO问题, 大幅度的提高性能(但也依赖特定的操作系统), 比基于JAVA的BIO和NIO都快不少.
安装APR的最低要求:
• APR 1.2+ development headers (libapr1-dev package)
• OpenSSL 1.0.2+ development headers (libssl-dev package)
• JNI headers from Java compatible JDK 1.4+
• GNU development environment (gcc, make)
确认包的版本:
dpkg -l <package-name>
# 如
dpkg -l libapr1-dev
虽然很多操作系统都自带APR和OpenSSL, 但版本可能不符合要求. 因此逐个安装.
安装APR:
apt install libapr1-dev
安装openSSL
apt install libssl-dev
安装GNU开发环境
apt install gcc make
编译安装tcnative
在tomcat/bin目录下找到tomcat-native.tar.gz
# 解压
tar xzf /opt/apache-tomcat-8.5.32/bin/tomcat-native.tar.gz
cd tomcat-native-1.2.17-src/native
# 配置,编译,安装
./configure && make && make install
安装成功的提示:
Libraries have been installed in:
/usr/local/apr/lib
为可执行文件做链接. 让linux可以从$PATH下找到它
此时linux在PATH下找不到apr, 因此还需要做软链接. 否则启动Tomcat会看到这样一个提示:
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_14/jre/lib/i386/server:/usr/local/jdk1.6.0_14/jre/lib/i386:/usr/local/jdk1.6.0_14/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
链接文件
ls /usr/local/apr/lib
ln -s /usr/local/apr/lib/libtcnative-1.so.0.2.17 libtcnative-1.so
ln -s /usr/local/apr/lib/libtcnative-1.so.0.2.17 libtcnative-1.so.0
此时APR安装完成, 可以尝试启动Tomcat.
启动Tomcat
cd /opt/apache-tomcat-8.5.32/bin
./startup.sh
从日志可以看到tomcat已经在使用apr了.