天天看點

jvisualvm下使用JMX方式遠端監控tomcat7

網上找了很多資料,折騰的大半天,結果不盡如人意,最終還是成功了,将過程寫下來,與大家分享一下。

運作環境:jdk1.6.0_23+tomcat7.0+;

測試内容,遠端監控tomcat下運作的應用。

步驟:

1.将CATALINA_HOME/conf下的server.xml中,加上下面一段:

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener?"
rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

2.将JAVA_HOME/jre/lib/management下jmxremote.access、jmxremote.password兩個檔案放到CATALINA_HOME/conf目錄裡面,如果沒有jmxremote.password,則從JAVA_HOME/jre/lib/management/jmxremote.password.template拷貝出一個名為jmxremote.password的新檔案, 修改檔案内容:

$CATALINA_BASE/conf/jmxremote.password containing:

admin letmein

$CATALINA_BASE/conf/jmxremote.access containing:

admin readwrite

3.在CATALINA_HOME/lib下加上catalina-jmx-remote.jar

4.修改CATALINA_HOME/bin/catalina.bat檔案,在rem ----- Execute The Requested Command ---------------------------------------下添加 set JAVA_OPTS= -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false

5.啟動tomcat,然後回到本地環境,打開jvisualvm,添加遠端主機,(e.g. 1.1.2.36),然後右鍵添加JMX連結,輸入端口:10001;輸入使用者名和密碼,即jmxremote.password中的内容,點選确定。

官方教程: http://tomcat.apache.org/tomcat-7.0-doc/config/listeners.html#JMX_Remote_Lifecycle_Listener_-_org.apache.catalina.mbeans.JmxRemoteLifecycleListener

jvisualvm下使用JMX方式遠端監控tomcat7