Tomcat可以使用APR來提供超強的可伸縮性和性能,更好地集成本地服務器技術。APR(Apache Portable Runtime)是一個高可移植庫,它是Apache HTTP Server 2.x的核心。APR有很多用途,包括訪問高級IO功能(例如sendfile,epoll和OpenSSL),OS級別功能(隨機數生成,系統狀態等等),本地進程管理(共享內存,NT管道和UNIX sockets)。這些功能可以使Tomcat作爲一個通常的前臺WEB服務器,能更好地和其它本地web技術集成,總體上讓Java更有效率作爲一個高性能web服務器平臺而不是簡單作爲後臺容器。
按照官方說明需要:
- APR library
- OpenSSL libraries
openssl 可以用 yum install openssl-devel,apr還是下載*.gz來安裝。
apr-1.3.2.tar.gz
apr-util-1.3.2.tar.gz
兩個可以在 http://apache.mirror.phpchina.com/apr/ 找到。
tomcat-native.tar.gz 可以在tomcat/bin目錄下找到。
安裝 apr
- # wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz
- # tar zxvf apr-1.3.2.tar.gz
- # cd apr-1.3.2
- # ./configure
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz
- # tar zxvf apr-1.3.2.tar.gz
- # cd apr-1.3.2
- # ./configure
- # make
- # make install
# wget http://apache.mirror.phpchina.com/apr/apr-1.3.2.tar.gz # tar zxvf apr-1.3.2.tar.gz # cd apr-1.3.2 # ./configure # make # make install
apr 默認安裝在 /usr/local/apr
安裝 apr-util
- # wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz
- # tar zxvf apr-util-1.3.2.tar.gz
- # cd apr-util-1.3.2
- # ./configure --with-apr=/usr/local/apr
- # make
- # make install
- # wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz
- # tar zxvf apr-util-1.3.2.tar.gz
- # cd apr-util-1.3.2
- # ./configure --with-apr=/usr/local/apr
- # make
- # make install
# wget http://apache.mirror.phpchina.com/apr/apr-util-1.3.2.tar.gz # tar zxvf apr-util-1.3.2.tar.gz # cd apr-util-1.3.2 # ./configure --with-apr=/usr/local/apr # make # make install
安裝 tomcat-native
- # cd /usr/local/tomcat-6.0.18/bin
- # tar zxvf tomcat-native.tar.gz
- # cd tomcat-native-1.1.14-src/jni/native
- # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11
- # make
- # make install
- # cd /usr/local/tomcat-6.0.18/bin
- # tar zxvf tomcat-native.tar.gz
- # cd tomcat-native-1.1.14-src/jni/native
- # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11
- # make
- # make install
# cd /usr/local/tomcat-6.0.18/bin # tar zxvf tomcat-native.tar.gz # cd tomcat-native-1.1.14-src/jni/native # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_11 # make # make install
設置 apr 的環境變量:
- # vi /etc/profile
- // 後面添加以下內容
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
- //使profile生效,
- # source /etc/profile
- # bin/startup.sh
- # head logs/catalina.out
- // 可以看到以下結果:
- 信息: Loaded APR based Apache Tomcat Native library 1.1.14.
- 2009-1-13 11:12:51 org.apache.catalina.core.AprLifecycleListener init
- 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
- # bin/startup.sh
- # head logs/catalina.out
- // 可以看到以下結果:
- 信息: Loaded APR based Apache Tomcat Native library 1.1.14.
- 2009-1-13 11:12:51 org.apache.catalina.core.AprLifecycleListener init
- 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
好了, 可以運行了,但沒有測試其性能提升多少。
參考自:http://www.chinajvm.com/main/helpcontent.jsp?id=5320b71a1eb098e2011ee230a2311367
http://blog.chenlb.com/2009/01/install-apache-portable-runtime-or-tomcat-native-on-tomcat.html