CentOS 7 Tomcat 8 9 基于APR库性能优化

Posted 大魔王

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7 Tomcat 8 9 基于APR库性能优化相关的知识,希望对你有一定的参考价值。

Tomcat可以使用Apache Portable Runtime来提供卓越的性能及可扩展性,更好地与本地服务器技术的集成。Apache Portable Runtime是一个高度可移植的库,位于Apache HTTP Server 2.x的核心。APR有许多用途,包括访问高级IO功能(如sendfile,epoll和OpenSSL),操作系统级功能(随机数生成,系统状态等)以及本地进程处理(共享内存,NT管道和Unix套接字)

这些功能不仅仅是一个后端集中的技术,还可以让Tomcat成为通用的网络服务器,可以实现与本地的其他Web技术更好的集成,并使Java成为一个完整的网络服务器平台

官方要求 :

APR 1.2+ development headers (libapr1-dev package)
OpenSSL 1.0.2+ development headers (libssl-dev package)
JNI headers from Java compatible JDK 1.4+
GNU development environment (gcc, make)

 

安装相关依赖包 : 

[[email protected] ~]# yum -y install gcc gcc-c++ libtool* autoconf automake expat-devel perl perl-devel

安装apr :

[[email protected] ~]# cd /tmp/
[[email protected] tmp]# wget http://mirrors.shu.edu.cn/apache/apr/apr-1.6.3.tar.gz
[[email protected] tmp]# tar xf apr-1.6.3.tar.gz 
[[email protected] tmp]# cd apr-1.6.3
[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.6.3]# make && make install

安装apr-iconv :

[[email protected] tmp]# wget http://mirrors.shu.edu.cn/apache/apr/apr-iconv-1.2.2.tar.gz
[[email protected] tmp]# tar xf apr-iconv-1.2.2.tar.gz 
[[email protected] tmp]# cd apr-iconv-1.2.2
[[email protected] apr-iconv-1.2.2]# ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
[[email protected] apr-iconv-1.2.2]# make && make install

安装apr-util :

[[email protected] tmp]# wget http://mirrors.shu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[[email protected] tmp]# tar xf apr-util-1.6.1.tar.gz 
[[email protected] tmp]# cd apr-util-1.6.1
[[email protected] 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
[[email protected] apr-util-1.6.1]# make && make install

安装openssl :

[[email protected] tmp]# wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz
[[email protected] tmp]# tar xf openssl-1.1.0h.tar.gz 
[[email protected] tmp]# cd openssl-1.1.0h
[[email protected] openssl-1.1.0h]# ./config --prefix=/usr/local/openssl
[[email protected] openssl-1.1.0h]# make -j 4 && make install

安装tomcat-native :

 

[[email protected] openssl-1.1.0h]# cd /usr/local/tomcat/bin/
[[email protected]ang bin]# tar xf tomcat-native.tar.gz
[[email protected] bin]# cd tomcat-native-1.2.17-src/native/
[[email protected] native]# ./configure --with-java-home=/usr/local/jdk10/  --with-ssl=/usr/local/openssl 
[[email protected] native]# make && make install

 

添加环境变量 :

[[email protected] native]# vim /etc/profile.d/jdk.sh
export LD_LIBRARY_PATH=/usr/local/apr/lib:$LD_LIBRARY_PATH
[[email protected] native]# source /etc/profile.d/jdk.sh
# 也可在catalina.sh中修改
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m" -Djava.library.path=/usr/local/apr/lib

配置server.xml

[[email protected] native]# cd /usr/local/tomcat/conf/
[[email protected] conf]# vim server.xml 
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
# 修改为
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
               connectionTimeout="20000"
               redirectPort="8443" />     
================================================================================
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
# 修改为
<Connector port="8009"         
                protocol="org.apache.coyote.ajp.AjpAprProtocol" 
                redirectPort="8443" />

查看日志验证

[[email protected] conf]# tail ../logs/catalina.2018-08-18.log 
18-Aug-2018 17:40:36.961 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
18-Aug-2018 17:40:36.997 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
18-Aug-2018 17:40:37.000 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 4032 ms

["http-apr-8080"] ["http-apr-8009"]可以看到已经以apr协议模式启动成功

 

 

 




以上是关于CentOS 7 Tomcat 8 9 基于APR库性能优化的主要内容,如果未能解决你的问题,请参考以下文章

tomcat7,8 centos7 配置apr极好教程

Tomcat8安装APR

CentOS6系统tomcat配置apr--踩坑之作

tomcat runing on daemon with apr and ssl mode

Centos6.9基于FPM模式编译安装实现LAMP应用wordpress

centos7 安装boots,提示bash: ./bootstrap.sh: 没有那个文件或目录