1、安装brew(软件管理安装工具)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装openssl(1.0.+)
brew install openssl
3、安装apr
brew install apr
4、安装tomcat-native
brew install tomcat-native —with-apr
5、安装tomcat(要求9.0+)
brew install tomcat —devel
6、创建setenv.sh
进入tomcat的bin目录,
cd /usr/local/Cellar/tomcat/9.0.0.M6/libexec/bin
vim setenv.sh
粘贴 CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=/usr/local/Cellar/tomcat-native/1.2.7/lib”
保存并推出esc—>:wq
执行setenv.sh文件
否则启动时报错
requires the APR/native library which is not available
7、生成证书
cd apache-tomcat-9.0.0.M6
mkdir ssl
cd ssl
openssl genrsa -out server.key 2048
openssl rsa -in server.key -out server.key
openssl req -new -x509 -key server.key -out ca.crt -days 3650
8、配置tomcat
cd apache-tomcat-9.0.0.M6/conf
vim server.xml
找到
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="conf/localhost-rsa-key.pem" certificateFile="conf/localhost-rsa-cert.pem" certificateChainFile="conf/localhost-rsa-chain.pem" type="RSA" /> </SSLHostConfig> </Connector>
去掉注释并修改为
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig honorCipherOrder="false" >
<Certificate certificateKeyFile="ssl/server.key"
certificateFile="ssl/ca.crt"
type="RSA" />
</SSLHostConfig>
</Connector>
保存并退出启动tomcat
9、访问
10、用谷歌浏览器测试是否是http2
打开chrome://net-internals/#http2检测
11、检查日志也可以,能看到**************http/2.0**********