Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Tomcat 服務重啟實戰:進程查找、強制終止、啟動驗證與日誌追蹤

編輯:Linux 教學

標準重啟流程

# 1. 查找 Java 進程
ps -ef | grep java
# 輸出範例:
# root   487   1  1 Jan20 ?  00:33:55 /usr/local/jdk1.7.0_75/jre/bin/java ... org.apache.catalina.startup.Bootstrap start

# 2. 強制終止進程 (PID 487)
kill -9 487

# 3. 切換到 Tomcat bin 目錄
cd /usr/local/tomcat7/bin

# 4. 執行啟動腳本
sh start.sh
# 輸出:
# Using CATALINA_BASE: /usr/local/tomcat7
# Using CATALINA_HOME: /usr/local/tomcat7
# Tomcat started.

# 5. 即時追蹤啟動日誌
tail -f /usr/local/tomcat7/logs/catalina.out

日誌關鍵節點確認

# 成功啟動標誌
INFO: Server startup in 15092 ms

# 典型啟動階段
Jan 22 14:49:05 ProtocolHandler ["http-bio-80"] 初始化
Jan 22 14:49:05 ProtocolHandler ["ajp-bio-8009"] 初始化
Jan 22 14:49:05 Catalina 初始化完成
Jan 22 14:49:05 StandardService 啟動
Jan 22 14:49:05 StandardEngine 啟動
Jan 22 14:49:16 SessionIdGenerator 建立 SecureRandom (耗時 10秒)
Jan 22 14:49:17-20 各 WebApp 部署完成 (docs, sdta_county, manager, examples, host-manager, ROOT)
Jan 22 14:49:20 ProtocolHandler 啟動完成

常見問題排查

現象可能原因處理方式
端口佔用 (Address already in use)舊進程未完全釋放、其他服務佔用 80/8009netstat -tulnp | grep :80 確認並 kill
SecureRandom 卡住熵池不足啟用 haveged 或 -Djava.security.egd=file:/dev/./urandom
WebApp 部署失敗類別衝突、資源不足、配置錯誤查看 catalina.out 堆疊追蹤、檢查 web.xml
記憶體溢位 (OOM)Heap/Metaspace 設定過小調整 CATALINA_OPTS="-Xms2g -Xmx4g -XX:MaxMetaspaceSize=512m"

優化建議

  • 建立重啟腳本 restart_tomcat.sh 封裝上述流程
  • 配置 catalina.out 日誌輪轉 (logrotate)
  • 生產環境建議使用 systemd 管理服務,而非直接呼叫 start.sh
  • 監控關鍵指標:JVM 記憶體、執行緒數、HTTP 回應時間、錯誤率
Copyright © Windows教程網 All Rights Reserved