Springboot 內置tomcat 基本配置收集整理


配置一:

server:
# tomcat 配置
  tomcat:
    # 接收隊列長度
    accept-count: 1000
    # 最小空閑線程數
    min-spare-threads: 100
    # POST請求提交大小
    max-http-form-post-size: 50MB
    # 最大鏈接數
    max-connections: 1000
    # 最大線程數
    max-threads: 400
    #編碼方式
    uri-encoding: UTF-8
    #鏈接建立超時時間
    connection-timeout: 10000
    #日志配配置
    accesslog:
      #是否啟用
      enabled: true
      #目錄
      directory: C:\logs\tomcat\${server.port}\
      #文件日期格式
      file-date-format: yyyy-MM-dd
      #前綴
      prefix: access_log
      #后綴
      suffix: .log
      #日志格式,默認為common,也可自定義配置
      pattern: combined

其他相關配置:

server.tomcat.basedir:配置 Tomcat 運行日志和臨時文件的目錄。若不配置,則默認使用系統的臨時目錄。

內存配置:

要加“m”說明是MB,否則就是KB.
-Xms:初始值
-Xmx:最大值
-Xmn:最小值
java -Xms10m -Xmx80m -jar mod.jar & 時區設置 java -jar -Duser.timezone=GMT+08
mod.jar &

Spring Boot項目同路徑下新建一同名配置文件

項目為boot.jar,新建文件boot.conf,項目啟動之后默認讀取該配置文件

1、jvm運行參數

JAVA_OPTS="-Xms2048m -Xmx2048m -Xss512k"

-Xms:初始Heap大小,使用的最小內存,cpu性能高時此值應設的大一些-Xmx:Java heap最大值,使用的最大內存

上面兩個值是分配JVM的最小和最大內存,取決於硬件物理內存的大小,建議均設為物理內存的一半。-XX:PermSize:設定內存的永久保存區域-XX:MaxPermSize:設定最大內存的永久保存區域-XX:MaxNewSize:-Xss 15120 這使得JBoss每增加一個線程(thread)就會立即消耗15M內存,而最佳值應該是128K,默認值好像是512k.+XX:AggressiveHeap 會使得 Xms沒有意義。這個參數讓jvm忽略Xmx參數,瘋狂地吃完一個G物理內存,再吃盡一個G的swap。-Xss:每個線程的Stack大小-verbose:gc 現實垃圾收集信息-Xloggc:gc.log 指定垃圾收集日志文件-Xmn:young generation的heap大小,一般設置為Xmx的3、4分之一-XX:+UseParNewGC :縮短minor收集的時間-XX:+UseConcMarkSweepGC :縮短major收集的時間

提示:此選項在Heap Size 比較大而且Major收集時間較長的情況下使用更合適。

2、項目運行參數

RUN_ARGS="--server.port=8081 --logging.level=INFO --spring.thymeleaf.cache=true --logging.file=/var/log/demo.lo

日志模式配置:

pattern的配置:

%a - Remote IP address,遠程ip地址,注意不一定是原始ip地址,中間可能經過nginx等的轉發
%A - Local IP address,本地ip
%b - Bytes sent, excluding HTTP headers, or ‘-’ if no bytes were sent
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false),遠程主機名稱(如果resolveHosts為false則展示IP)
%H - Request protocol,請求協議
%l - Remote logical username from identd (always returns ‘-‘)
%m - Request method,請求方法(GET,POST)
%p - Local port,接受請求的本地端口
%q - Query string (prepended with a ‘?’ if it exists, otherwise an empty string
%r - First line of the request,HTTP請求的第一行(包括請求方法,請求的URI)
%s - HTTP status code of the response,HTTP的響應代碼,如:200,404
%S - User session ID
%t - Date and time, in Common Log Format format,日期和時間,Common Log Format格式
%u - Remote user that was authenticated
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis,處理請求的時間,單位毫秒
%T - Time taken to process the request, in seconds,處理請求的時間,單位秒
%I - current Request thread name (can compare later with stacktraces),當前請求的線程名,可以和打印的log對比查找問題


免責聲明!

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



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