1. 程式人生 > >windows通過VisualVM遠端監控linux下的tomcat使用情況

windows通過VisualVM遠端監控linux下的tomcat使用情況

在網上找了可以說是n多文章呀,都配置過,但都不行,可能是我一開始tomcat裡面的檔案搞亂了吧,後來把tomat給刪掉,重新解壓一份,一步一步參照官方文件給出的解決方案,終於給解決了

1、在tomcat的安裝目錄下的conf/server.xml加上

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


2、在tomcat安裝目錄bin/下新建setenv.sh檔案,檔案內容為

#!/bin/sh

-Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password
-Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access
-Dcom.sun.management.jmxremote.ssl=false

這個地方可能會報錯,


也沒找錯誤原因,如果那位大神知道的話可以留言告知一下。我的解決方法是在環境變數/etc/profile下增加下面程式碼:

export JAVA_OPTS="-Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false"

然後啟動tomcat就沒出現之前那個錯誤了。 3、在第二部裡面對應的$CATALINA_BASE即是/opt/tomcat/(我的是這個),這個不用去關心,但是在這之前有關tomcat的環境變數請自行設定好,我這邊就在/etc/profile下面設定了,CATALINA_HOME即是應該設定的tomcat的環境,當然java環境變數也要設定好


setenv.sh檔案的jmxremote.password和jmxremote.access在/opt/java/jdk1.6.0_45/jre/lib/management下面會發現對應jmxremote.access和jmxremote.password.template複製到tomcat安裝目錄下的conf資料夾下就OK了,jmxremote.password.template複製過去的時候要改名成jmxremote.password,然後在這兩個檔案裡面新增以下內容,圖示:

jmxremote.password:


jmxremote.access:


4、接著開啟linux防火牆對10001和10002設定,之前在某篇文章下面看到,埠值在幾千一下就不用設定,但是我這個地方一開始就設定了,所以就沒去掉了。設定埠可以在linux執行命令  vi /etc/sysconfig/iptables,這裡給出截圖:


-A INPUT -m state --state NEW -m tcp -p tcp --dport 10001 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10002 -j ACCEPT

即上面這兩句。

5、往tomcat安裝檔案lib資料夾加入catalina-jmx-remote.jar這個檔案

6、更改/etc/hosts下面的127.0.0.1或localhost為你的真實IP地址,然後用命令hostname -i檢視

7、開啟visualvm,如圖


上面這個截圖的jaxremote.passwd寫錯了,你懂的。

歡迎大家拍磚。