使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文件的輸出:


這句話告訴我們沒有使用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


>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












發佈了197 篇原創文章 · 獲贊 35 · 訪問量 32萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章