使Tomcat使用APR

首先看来自apache官方的介绍:

Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets).

These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology.

安装流程:

一、判断您的tomcat是否使用apr

启动Tomat后观察TOMCAT_HOME/logs/catalina.out文件的输出:

使Tomcat使用APR_第1张图片

这句话告诉我们没有使用apr:

The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_32/jre/lib/
i386/server:/usr/java/jdk1.6.0_32/jre/lib/i386:/usr/java/jdk1.6.0_32/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib

二、下载相关安装文件

下载位置:http://apr.apache.org/download.cgi

使Tomcat使用APR_第2张图片

>wget http://mirror.bit.edu.cn/apache//apr/apr-1.4.6.tar.gz

>wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.1.tar.gz

>wget http://mirror.bit.edu.cn/apache//apr/apr-iconv-1.2.1.tar.gz

解压三个包

>tar -zxvf apr-1.4.6.tar.gz

>tar -zxvf apr-util-1.5.1.tar.gz

>tar -zxvf apr-iconv-1.2.1.tar.gz

三、安装:

[root@localhost apr-1.4.6]# ./configure && make && make install
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
Configuring APR library
Platform: i686-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.4.6
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/download/apr-1.4.6':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost apr-1.4.6]# 

上面的提示告诉我们c编译器不正确,我们重新安装gcc

>yum list available gcc*

[root@localhost apr-1.4.6]# yum list available gcc*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
Available Packages
gcc.i686                                                                                  4.4.6-4.el6                                                                          base
gcc-c++.i686                                                                              4.4.6-4.el6                                                                          base
gcc-gfortran.i686                                                                         4.4.6-4.el6                                                                          base
gcc-gnat.i686                                                                             4.4.6-4.el6                                                                          base
gcc-java.i686                                                                             4.4.6-4.el6                                                                          base
gcc-objc.i686                                                                             4.4.6-4.el6                                                                          base
gcc-objc++.i686                                                                           4.4.6-4.el6                                                                          base

安装

>yum install gcc.i686 -y

耐心等待,要安装好一会儿

如果make 命令不能使用还要安装

>yum -y install automake autoconf libtool make

继续安装

>./configure && make && make install

查看apr是否安装完成

>find /usr -name apr

[root@localhost apr-1.4.6]# find / -name apr
/usr/local/apr

安装apr-util

apr-util-1.5.1>./configure --with-apr=/usr/local/apr

apr-util-1.5.1>make && make install


安装apr-iconv

apr-iconv-1.2.1>./configure --with-apr=/usr/local/apr

apr-iconv-1.2.1>make && make install


继续安装tomcat_native.tar.gz,这个文件位于TOMCAT_HOME/bin下面

[root@localhost bin]# tar -zxvf tomcat*.gz

[root@localhost bin]# cd tomcat*

[root@localhost tomcat-native-1.1.24-src]# cd jni/native

[root@localhost native]# ./configure --with-apr=/usr/local/apr

注意如果没有为JDK配置环境变量那么上面的./confiugre是会执行失败的,要为JDK配置环境变量请在/etc/profile末尾添加

export JAVA_HOME=/usr/java/jdk1.6.0_32
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$PATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

然后使用以下命令使环境变量生效

source /etc/profile

[root@localhost native]#make && make install

为apr库配置环境变量,在/etc/profile末尾添加

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

然后使用以下命令使环境变量生效

source /etc/profile

重新启动tomcat观察catalina.out:
[root@localhost native]# more /usr/tomcat7/logs/catalina.out
2013-2-20 20:41:27 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.24 using APR version 1.4.6.
2013-2-20 20:41:27 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2013-2-20 20:41:27 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
严重: Failed to initialize the SSLEngine.


到此TOMCAT已经使用APR












你可能感兴趣的:(使Tomcat使用APR)