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.