利用APR本地庫提高Tomcat性能

ptjs 12年前發布 | 3K 次閱讀 5.2.1版本發布

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服務器平臺而不是簡單作為后臺容器。

  在產品環境中,特別是直接使用Tomcat做WEB服務器的時候,您應該使用Tomcat Native來提高其性能,詳細配置和安裝請參考Tomcat文檔。

如果沒有apr技術,啟動tomcat 時出現如下提示:

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_06/jre/lib/i386/client:/usr/java/jdk1.6.0_06/jre/lib/i386:/usr/java/jdk1.6.0_06/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib

 

按照官方說明需要:

·        APR library

·        OpenSSL libraries

openssl 可以用 yum install openssl-devel,apr還是下載*.gz來安裝。
下載https://archive.apache.org/dist/apr/

apr-1.4.6.tar.gz
apr-util-1.4.1.tar.gz
tomcat-native.tar.gz
可以在tomcat/bin目錄下找到。

1、安裝 apr

1.    # tar zxvf apr-1.4.6.tar.gz  

2.    # cd apr-1.4.6  

3.    # ./configure  

4.    # make  

5.    # make install  

備注:apr 默認安裝在 /usr/local/apr

2、安裝 apr-util

1.    # tar zxvf apr-util-1.4.1.tar.gz  

2.    # cd apr-util-1.4.1  

3.    # ./configure --with-apr=/usr/local/apr  

4.    # make  

5.    # make install  

安裝好了之后會有個提示:----------------------------------------------------------

Libraries have been installed in:

   /usr/local/apr/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr/lib

/usr/bin/install -c -m 755 apu-config.out /usr/local/apr/bin/apu-1-config

[root@business apr-util-1.4.1]#

-------------------------------------------------------------------

3、安裝 tomcat-native

1.    # cd /usr/local/tomcat-6.0.33/bin  

2.    # tar zxvf tomcat-native.tar.gz  

3.    # cd tomcat-native-1.1.20-src/jni/native  

4.    # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.7.0  

5.    # make  

6.    # make install

----------------------------------------------------------------------

Libraries have been installed in:

   /usr/local/apr/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

[root@business native]#

4、設置 apr的環境變量:

1.    # vi /etc/profile  

2.    // 后面添加以下內容 

3.    APR_HOME=/usr/local/apr 

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

5.    //使profile生效,  

6.    # source /etc/profile   

5、啟動 tomcat后, 看日志:

1.    # bin/startup.sh  

2.    # head logs/catalina.out  

3.    // 可以看到以下結果:  

4.    信息: Loaded APR based Apache Tomcat Native library 1.1.20.  

5.    2009-1-13 11:12:51 org.apache.catalina.core.AprLifecycleListener init  

6.    APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].  

server.xml文件中

<Connector port="8888" executor="tomcatThreadPool" protocol="org.apache.coyote.http11.Http11AprProtocol"  connectionTimeout="40000" redirectPort="8444" maxThreads="800" 

enableLookups="false" acceptCount="1000" disableUploadTimeout="true"/>

protocol 這一項也可以不改。

 本文由用戶 ptjs 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!