您的位置:首页 > 运维架构 > Tomcat

APR安装部署提高Tomcat性能

2012-09-27 14:30 323 查看
利用APR本地库提高Tomcat性能
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 这一项也可以不改。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: