CentOS安装、配置APR和tomcat-native

APRApache Portable Run-time libraries,Apache可移植执行库
在早期的Apache版本号中。应用程序本身必须可以处理各种详细操作系统平台的细节,并针对不同的平台调用不同的处理函数。

随着Apache的进一步开发。Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样。APR的开发就从Apache中独立出来,Apache不过使用APR而已。


Tomcat Native:这个项目能够让 Tomcat 使用 Apache 的 apr 包来处理包含文件和网络IO操作,以提升性能。
官网介绍:
The Apache Tomcat Native Library is an optional component for use with Apache Tomcat that allows Tomcat to use certain native resources for performance, compatibility, etc.
(大概意思是Tomcat能够利用一些native资源来提高性能和兼容性。


Specifically, the Apache Tomcat Native Library gives Tomcat access to the Apache Portable Runtime (APR) library's network connection (socket) implementation and random-number generator. 
(详细来说是利用了APR库中的网络连接实现和随机数生成器。)

Features of the APR connector:

  • Non-blocking I/O for Keep-Alive requests (between requests)
  • Uses OpenSSL for TLS/SSL capabilities (if supported by linked APR library)
  • FIPS 140-2 support for TLS/SSL (if supported by linked OpenSSL library)

Linux下,Tomcat启用APR须要三个组件:
  • apr
  • apr-util
  • tomcat-native.tar.gz(Tomcat自带,在bin文件夹下)

1、查看是否已经安装了apr和apr-util
# rpm -qa apr
apr-1.4.8-3.el7.x86_64

# rpm -qa apr-util
apr-util-1.5.2-6.el7.x86_64

2、查看是否有最新版的apr和apr-util
# yum list | grep apr
apr.x86_64                              1.4.8-3.el7                    @anaconda
apr-util.x86_64                         1.5.2-6.el7                    @anaconda

3、假设还没安装,用yum安装:
# yum install apr-devel apr apr-util

4、安装tomcat-native:
搜索tomcat-native安装包:
# yum list | grep tomcat-native

假设已经存在,直接安装:
# yum install tomcat-native
……
  正在安装    : tomcat-native-1.1.30-1.el7.x86_64        1/1
  验证中      : tomcat-native-1.1.30-1.el7.x86_64         1/1

已安装:
  tomcat-native.x86_64 0:1.1.30-1.el7                                                                                                                                                        
完成!

查看是否成功安装:
# rpm -qa tomcat-native
tomcat-native-1.1.30-1.el7.x86_64

配置相关的全局变量:
# vi /etc/profile
加入:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
# source /etc/profile

5、重新启动Tomcat。看看能否够成功使用APR
假设一切正常:
APR启动:
[main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-18080"]
[main] org.apache.catalina.startup.Catalina.start Server startup in 13617 ms
相比NIO模式的启动,速度快了一些(~15%):
NIO启动:
[main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-18080"]
[main] org.apache.catalina.startup.Catalina.start Server startup in 15671 ms

假设发现异常log,比方:
06-Aug-2015 14:46:04.949 SEVERE [main] org.apache.catalina.core.AprLifecycleListener.init An incompatible version 1.1.30 of the APR based Apache Tomcat Native library is installed, while Tomcat requires version 1.1.32

说明系统自带的tomcat-native版本号太低。
删除:
# yum erase tomcat-native

用yum检查有没有最新版:
# yum update tomcat-native
假设yum找不到最新版。则下载或从Tomcat/bin中解压安装。

从Tomcat/bin文件夹中,解压tomcat-native.tar.gz文件:
# tar -zxvf tomcat-native.tar.gz
得到目录:tomcat-native-1.1.33-src
# cd tomcat-native-1.1.33-src/jni/native/
# ./configure --with-apr=/usr/local/apr    (官网中样例的其它參数不须要,会自己主动找到
# make && make install

參考:
官网的安装指导:http://tomcat.apache.org/native-doc/
Tomcat Connector三种执行模式(BIO, NIO, APR)的比較和优化:http://blog.csdn.net/clementad/article/details/47045673

(原创文章,转载请注明转自Clement-Xu的博客)

posted on 2017-05-23 13:59  blfbuaa  阅读(5699)  评论(0编辑  收藏  举报