Tomcat 安裝和配置

安裝:web

  1. 下載安裝包解壓 http://tomcat.apache.org/download-80.cgi
  2. 進入bin文件夾,./startup.sh開啓Tomcat,./shutdown.sh關閉Tomcat
  3. 進入conf文件夾,配置tomcat-users.xml配置用戶
  4. 打開localhost:8080/管理Tomcat,經過Tomcat管理界面或者idea部署war包便可部署;]
  5. 默認部署到webapps目錄下,war的訪問前綴爲包名springboot.war即爲localhost:8080/springboot/


配置:spring

  1. tomcat-users.xml配置用戶
    <role rolename="admin-gui"/>   #admin gui用戶
    <role rolename="manager-gui」/> #manager gui用戶
    <user username="admin" password="admin" roles=" admin-gui , manager-gui "/>

     

  2. server.xml配置Tomcat
    <!—配置線程池-->
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
           maxThreads="150" minSpareThreads=「4」 maxIdleTime=「60000"/>
    
    <!--設置監聽端口,設置共享線程池提升性能-->
    <!--設置爲nio protocol="org.apache.coyote.http11.Http11NioProtocol" -->
    <!--tomcat8之後默認爲nio -->
    <Connector executor="tomcatThreadPool"
                 port="8080" protocol="HTTP/1.1"
                 connectionTimeout="20000"
                 enableLookups=「false"
                 redirectPort="8443" />
    
    <!-- https配置 -->
    <Connector executor="tomcatThreadPool" port="443" protocol="HTTP/1.1" 
                SSLEnabled=「true"  scheme="https" secure="true" clientAuth="false" 
                sslProtocol=「TLS" keystoreFile="conf/tomcat.keystore" keystorePass="123456"/>
    
    <!--設置war目錄以及部署屬性,能夠配置多個Host對應多個域名綁定-->
    <Host name="localhost"
                appBase="webapps"
                unpackWARs="true" autoDeploy="true">

     

  3. web.xml配置容許跨域請求
    <filter>
        <filter-name>CorsFilter</filter-name>
        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CorsFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

     
  4. catalina.sh中配置jvm內存,具體參數參考機器配置
    JAVA_OPTS = "-Xmx1024m -Xms1024m -Xmn400m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -Xloggc:/usr/local/tomcat/logs/gc.log」
    cygwin=false
     
  5. server.xml配置靜態資源映射
相關文章
相關標籤/搜索