Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux (CentOS) 安裝 JProfiler 8 並配置 Tomcat 遠程性能分析

編輯:Linux 系統常見問題解答

環境準備

  • JDK:已配置 JAVA_HOME、PATH (如 /usr/local/jenkins/jdk1.6.0_37)。
  • Tomcat:已部署運行 (如 /usr/local/tomcat)。
  • 系統:CentOS 7+,開放防火牆端口 (默認 JProfiler 代理端口 8849)。

JProfiler 安裝 (無頭模式)


# 1. 下載 Linux 版 (無 GUI 安裝包)
wget https://download-aws.ej-technologies.com/jprofiler/jprofiler_linux_8_0_4.tar.gz

# 2. 解壓
tar xf jprofiler_linux_8_0_4.tar.gz -C /usr/local/
# 產生 /usr/local/jprofiler8

# 3. 設置執行權限
chmod +x /usr/local/jprofiler8/bin/*.sh

生成 Tomcat 啟動腳本 (關鍵步驟)

在有圖形界面的機器 (Windows/Mac/Linux Desktop) 運行 JProfiler GUI 完成配置向導:

  1. 菜單 Session → Integration Wizards → New Remote Integration。
  2. 選擇 Apache Tomcat → 下一步。
  3. Tomcat 版本選擇 (如 7.x/8.x/9.x)。
  4. 配置連接方式:Named Pipe (Windows) 或 TCP Socket (Linux),端口默認 8849。
  5. 選擇 Tomcat 安裝目錄 (本地路徑),向導會讀取 bin/startup.sh。
  6. 完成向導,生成 startup_jprofiler.sh 腳本 (位於 Tomcat bin/ 目錄)。

部署到遠程 Linux 服務器


# 1. 上傳生成的 startup_jprofiler.sh 到遠程 Tomcat bin 目錄
scp startup_jprofiler.sh user@remote:/usr/local/tomcat/bin/

# 2. 上傳 JProfiler agent 動態庫 (Linux x64)
scp -r /usr/local/jprofiler8/bin/linux-x64 user@remote:/usr/local/jprofiler8/bin/

# 3. 遠程服務器授權
chmod +x /usr/local/tomcat/bin/startup_jprofiler.sh

啟動與連接


# 遠程服務器啟動 Tomcat (帶 JProfiler agent)
cd /usr/local/tomcat/bin
./startup_jprofiler.sh

# 本地 JProfiler GUI 連接
# Session → Attach to Running JVM → Remote → 輸入 IP:8849

生成的 startup_jprofiler.sh 關鍵內容解析


#!/bin/sh
# JProfiler agent 路徑 (需與遠程服務器實際路徑一致)
JPROFILER_AGENT_PATH="/usr/local/jprofiler8/bin/linux-x64/libjprofilerti.so"

# JVM 參數注入
JAVA_OPTS="$JAVA_OPTS -agentpath:$JPROFILER_AGENT_PATH=port=8849,nowait"

# 原有啟動邏輯
exec "$CATALINA_HOME/bin/catalina.sh" start "$@"

常見問題排查

現象原因解決
連接超時防火牆阻擋 8849 端口firewall-cmd --add-port=8849/tcp --permanent && firewall-cmd --reload
Agent 加載失敗libjprofilerti.so 路徑錯誤或架構不匹配 (x64 vs aarch64)檢查 uname -m 對應上傳正確 agent 目錄
Tomcat 啟動卡住agent 參數 nowait 缺失,JProfiler 等待 GUI 連接確保 agentpath 含 nowait 或 GUI 先啟動連接
版本不兼容JProfiler 8 不支持 JDK 11+升級 JProfiler 11+ 或降級 JDK 8

安全建議

  • 生產環境嚴禁直接暴露 8849 端口至公網,使用 SSH 隧道轉發:ssh -L 8849:localhost:8849 user@remote,本地連接 localhost:8849。
  • 分析完成後及時停止 agent (關閉 Tomcat 或移除 agentpath 參數重啟),避免性能開銷。
Copyright © Windows教程網 All Rights Reserved