1.安装相关依赖包
# yum -y install gcc gcc-c++ libtool* autoconf automake expat-devel perl perl-devel
2.下载安装包
# cd /tmp/
# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-iconv-1.2.2.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
# wget https://www.openssl.org/source/openssl-1.1.0j.tar.gz
3.安装APR
# tar zxvf apr-1.6.5.tar.gz
# cd apr-1.6.5# vim configure
默认值:
RM='$RM'
修改为:
RM='$RM -f'
# ./configure --prefix=/usr/local/apr
# make && make install
4.安装apr-iconv
# tar zxvf apr-iconv-1.2.2.tar.gz
# cd apr-iconv-1.2.2
# ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
# make && make install
5.安装apr-util
# tar zxvf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
# make && make install
6.安装OpenSSL
# tar zxvf openssl-1.1.0j.tar.gz
# cd openssl-1.1.0j
# ./config --prefix=/usr/local/openssl
# make -j 4 && make install
7.安装tomcat-native
# cd /usr/local/tomcat/bin/
# tar zxvf tomcat-native.tar.gz
# cd tomcat-native-1.2.12-src/native
# ./configure --with-ssl=/usr/local/openssl --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/java/jdk1.8.0_131
# make && make install
注意:如果以上 configure 失败,可以执行 make distclean 清除
8.添加变量内容
# vim /etc/profile.d/jdk.shexport LD_LIBRARY_PATH=/usr/local/apr/lib:$LD_LIBRARY_PATH
# source /etc/profile.d/jdk.sh
至此APR安装成功。
9.接下来需要修改tomcat配置文件中的APR运行模式,并测试是否安装成功。
# vim /usr/local/tomcat/conf/server.xml
默认值:
修改为:
默认值:
修改为:
10.现在重启tomcat服务,并查看启动日志
# systemctl restart tomcat
# cat /usr/local/tomcat/logs/catalina.out
...INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/readINFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read...
注意:可以看到红色部分,提示找不到基于APR的Apache Tomcat Native库,因此无法使用APR模式启动。
解决方案:
# cp -R /usr/local/apr/lib/* /usr/lib64
# cp -R /usr/local/apr/lib/* /usr/lib
再次重启tomcat,并查看启动日志
# cat /usr/local/tomcat/logs/catalina.out
...INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8009"]...
可以看到已经以apr协议模式启动成功,经基于APR的技术web压力测试,Tomcat的性能飙升。