CentOS7 + JDK1.8 + Tomcat8.5 实现HTTP/2.0、 http2 服务

HTTP协议以及HTTP2.0/1.1/1.0区别

需要在操作系统中安装libtcnative

一、环境准备

1.1  安装APR

下载apr-1.7.0.tar.gz、apr-util-1.6.1.tar.gz ,下载地址 https://mirror.bit.edu.cn/apache/apr/

上传至 /home 目录下后解压;

执行: 

#cd /home/apr-1.7.0
#./configure
#make
#make install
cd /home/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

 1.2 下载安装openSSL,地址 https://www.openssl.org/source/

cd /home/openssl
./config
make
make install

1.3 下载安装Tomcat Native,地址 http://tomcat.apache.org/download-native.cgi

同样解压后执行:

cd /home/tomcat-native-1.2.24-src/native
./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/openssl --with-java-home=${JAVA_HOME}
make
make install

1.4 配置 /etc/profile 文件,在末尾追加红色信息:

unset i
unset -f pathmunge

if [ -n "${BASH_VERSION-}" ] ; then
        if [ -f /etc/bashrc ] ; then
                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc
                # Check for double sourcing is done in /etc/bashrc.
                . /etc/bashrc
       fi
fi

export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export HADOOP_HOME=/home/hadoop-3.3.0
export HIVE_HOME=/home/hive-3.1.2
export CLASSPATH=$($HADOOP_HOME/bin/hadoop classpath):$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH:$HIVE_HOME/bin:$JAVA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/apr/lib:$LD_LIBRARY_PATH

 二、配置tomcat 8.5

1、在/home/apache-tomcat-8.5-jjdemo/bin  目录中创建setenv.sh文件, 内容如下:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
export LD_LIBRARY_PATH

2、修改server.xml 文件的Connector 节点信息:

    <Connector port="936"               
keepAliveTimeout
="15" maxKeepAliveRequests="200" maxThreads="5000" minSpareThreads="50" acceptCount="500" acceptorThreadCount="500" URIEncoding="UTF-8" enableLookups="false" compression="on" compressionMinSize="10240" noCompressionUserAgents="gozilla,traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" connectionTimeout="20000" disableUploadTimeout="true" protocol="org.apache.coyote.http11.Http11Nio2Protocol" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="conf/cert/4016613_jjdemo.xuetz.com.key" certificateFile="conf/cert/4016613_jjdemo.xuetz.com.pem" type="RSA" /> </SSLHostConfig> </Connector>

其中证书从阿里云SSL证书的“其他”类别中下载:

3、重启tomcat 查看日志信息,出现以下信息表示配置成功:

27-Aug-2020 11:01:51.545 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/home/apache-tomcat-8.5-jjdemo/temp
27-Aug-2020 11:01:51.545 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.24] using APR version [1.7.0].
27-Aug-2020 11:01:51.545 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
27-Aug-2020 11:01:51.545 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
27-Aug-2020 11:01:51.552 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2u  20 Dec 2019]
27-Aug-2020 11:01:51.662 INFO [main] org.apache.coyote.http11.AbstractHttp11Protocol.configureUpgradeProtocol The ["https-openssl-nio2-996"] connector has been configured to support negotiation to [h2] via ALPN
27-Aug-2020 11:01:51.663 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-openssl-nio2-996"]

4、访问页面后,查看localhost_access_log.2020-08-27.txt 文件,出现HTTP/2.0表示运行成功:

110.87.56.235 - - [27/Aug/2020:11:02:38 +0800] "GET /jjdemo/page/main.jsp HTTP/2.0" 302 -
110.87.56.235 - - [27/Aug/2020:11:02:39 +0800] "GET /jjdemo/page/loginXuetz.jsp HTTP/2.0" 200 8425
110.87.56.235 - - [27/Aug/2020:11:02:39 +0800] "GET /jjdemo/base/user/imageCode?width=150 HTTP/2.0" 200 1979
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "POST /jjdemo/base/user/doLogin HTTP/2.0" 200 29
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "GET /jjdemo/page/main.jsp HTTP/2.0" 200 15956
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "GET /rescore/easyui/themes/default/images/loading.gif HTTP/2.0" 404 1048
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "GET /rescore/easyui/themes/default/images/loading.gif HTTP/2.0" 404 1048
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "POST /jjdemo/esm/api/visit/count HTTP/2.0" 200 60
110.87.56.235 - - [27/Aug/2020:11:02:45 +0800] "POST /jjdemo/esm/api/visit/week HTTP/2.0" 200 51

 create by lixiaojia   2020-08-27

posted @ 2020-08-27 11:31  李小加  阅读(730)  评论(0编辑  收藏  举报