Tomcat 使用Apache Portable Runtime (APR) library从操作系统级别来提升异步的IO性能
需要安装的工具:apr apr-iconv apr-util tomcat-native
下载地址:http://apr.apache.org/download.cgi
tomcat-native在tomcat的bin文件夹
安装 apr
tar zxvf apr-1.5.2.tar
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make
make install
安装 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
安装 apr-util
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
make
make install
安装 tomcat-native
tar zxvf tomcat-native.tar.gz
cd tomcat-native-1.1.32-src/jni/native
./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/java/jdk1.6.0_45
make
make install
添加环境变量
vi /etc/profile #在文件末尾处添加下面的变量
export LD_LIBRARY_PATH=/usr/local/apr/lib
然后执行下面命令,使环境变量即时生效
source /etc/profile
验证
启动Tomcat:( ./start.sh && tail -f ../logs/catalina.log )
Tomcat启动的过程中,如果看到类似下面这样的信息,就证明apr安装成功了。
Jan 7, 2016 5:50:46 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library 1.1.32 using APR version 1.5.2.
Tomcat启动的过程中,如果看到类似下面这样的信息,如果没有用到HTTPS的话,可以忽略掉
SEVERE: Failed to initialize the SSLEngine.
org.apache.tomcat.jni.Error: 70023: This function has not been implemented on this platform
Tomcat启动的过程中,如果看到类似下面这样的信息,请检查下环境变量配置是否有问题(有时候从别处直接粘贴到/etc/profile看着很正常,其实可能会有问题):
echo $LD_LIBRARY_PATH 如果没有内容输出,自己手动重写一遍就好了
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/java/jdk1.6.0_45/jre/lib/amd64/
server:/usr/local/java/jdk1.6.0_45/jre/lib/amd64:/usr/local/java/jdk1.6.0_45/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
为了更完整,修改下tomcat安装目录下配置文件server.xml:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000" maxThreads="500" enableLookups="false"
redirectPort="8443"/>
到此APR和tomcat-native安装就结束了。