1、安装相关依赖包 # yum -y install gcc gcc-c++ libtool* autoconf automake expat-devel perl perl-devel
2、下载安装包 cd downsofe https://mirrors.tuna.tsinghua.edu.cn/apache//apr/ wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-iconv-1.2.2.tar.gz wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
3、安装APR
# tar zxvf apr-1.7.0.tar.gz # cd apr-1.7.0 # 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.0f.tar.gz # cd openssl-1.1.0f # ./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.8-src/native # echo $JAVA_HOME # ./configure --with-ssl=/usr/local/openssl --with-apr=/usr/local/apr --with-java-home=/usr/local/java/jdk1.8.0_271 # make && make install 注意:如果以上 configure 失败,可以执行 make distclean 清除
8、配置相关的全局变量:
# vi /etc/profile
加入:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
# source /etc/profile
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/read INFO [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协议模式启动成功。