Centos下Tomcat 安装Apache Portable Runtime

时间:2023-11-24 20:45:26

APR(Apache Portable Runtime)是一个高可移植库,它是Apache HTTP Server 2.x的核心。

APR有很多用途,包括访问高级IO功能(例如sendfile,epoll和OpenSSL),OS级别功能(随机数生成,系统状态等等),本地进程管理(共享内存,NT管道和UNIX sockets)。这些功能可以使Tomcat作为一个通常的前台WEB服务器,能更好地和其它本地web技术集成,总体上让Java更有效率作为一个高性能web服务器平台而不是简单作为后台容器。在Tomcat中使用JNI的方式来读取文件以及进行网络传输。这个东西可以大大提升Tomcat对静态文件的处理性能,同时如果你使用了HTTPS方式 传输的话,也可以提升SSL的处理性能。

安装过程

1. 下载所需的安装包

到http://apr.apache.org/下载
apr-1.5.2.tar.gz
apr-iconv-1.2.1.tar.gz
apr-util-1.5.4.tar.gz

到http://archive.apache.org/dist/tomcat/tomcat-connectors/native/下载
tomcat-native-1.1.33-src.tar.gz

2. 安装依次安装 apr, apr-iconv, apr-util, tomcat-native
tomcat-native的安装参数可以参考 http://tomcat.apache.org/native-doc/

tar zxvf apr-1.5..tar.gz
cd apr-1.5.
./configure --prefix=/usr/local/share/apr
sudo make
sudo make install tar zxvf apr-iconv-1.2..tar.gz
cd apr-iconv-1.2.
./configure --prefix=/usr/local/share/apr-iconv --with-apr=/usr/local/share/apr
sudo make
sudo make install tar zxvf apr-util-1.5..tar.gz
cd apr-util-1.5.
./configure --prefix=/usr/local/share/apr-util --with-apr=/usr/local/share/apr --with-apr-iconv=/usr/local/share/apr-iconv/bin/apriconv
sudo make
sudo make install tar zxvf tomcat-native-1.1.-src.tar.gz
cd tomcat-native-1.1.-src/jni/native/
./configure --with-apr=/usr/local/share/apr --with-java-home=/usr/java/jdk1..0_45 --prefix=/opt/tomcat
sudo make
sudo make install

注意, 最后一步指定了tomcat-native的安装路径是tomcat的安装目录, 而且安装结果会提示你

Libraries have been installed in:
/opt/tomcat/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'

所以你要把这个放到系统路径里

sudo vi /etc/profile

Add to last line

export LD_LIBRARY_PATH=/opt/tomcat/lib

保存之后, 在启动tomcat的用户环境下 source /etc/profile, 然后重启tomcat. 安装成功时, tomcat的启动日志会显示类似这样的信息

May ,  :: PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1. using APR version 1.5..
May , :: PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
May , :: PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8080"]