Tomcat 安装与配置规范
Tomcat 安装
演示版本:8.5.32 安装版
JDK推荐版本:jdk1.8
下载地址:https://tomcat.apache.org/download-80.cgi
安装教程
注意:tomcat8.5以后的版本,这样配置是无法进入管理页面的,客户端进入tomcat首页点击manager想进行项目管理发现没有登录提示,直接跳转403或401权限错误。我们需要修改相应的配置文件方可访问。
修改:/webapps/magager/META-INF/context.xml
原文为:
<Context antiResourceLocking="false" privileged="true" > <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context>
修改为:
<Context antiResourceLocking="false" privileged="true" > <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context>
tomcat并发调优处理:
修改server.xml
<Executor name="tomcatThreadPool" namePrefix="HTTP-8115-exec-" prestartminSpareThreads="true" maxThreads="5000" minSpareThreads="20" maxSpareThreads="50" maxIdleTime="1000"/> <Connector executor="tomcatThreadPool" port="8115" protocol="org.apache.coyote.http11.Http11NioProtocol" URIEncoding="UTF-8" connectionTimeout="30000" enableLookups="false" disableUploadTimeout="false" connectionUploadTimeout="150000" acceptCount="300" keepAliveTimeout="120000" maxKeepAliveRequests="1" compression="on" compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,image/gif,image/jpg,image/png" redirectPort="8443" />
增加全局错误页面处理
准备一个错误处理页面404.html和500.html(内容自定义)
把error.html放到\webapps\ROOT目录下
修改web.xml增加下图代码
<error-page> <exception-type>java.lang.Exception</exception-type> <location>/500.html</location> </error-page> <error-page> <error-code>404</error-code> <location>/404.html</location> </error-page> <error-page> <error-code>500</error-code> <location>/500.html</location> </error-page>
增加tomcatq启动内存
-XX:PermSize=512M
-XX:MaxPermSize=1024M