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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM