Java VisualVM對tomcat性能監控



  • 從官網下載Tomcat對應版本的catalina-jmx-remote.jar(這個使用Tomcat 7.0.81版本)python

Tomcat下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.81/bin/apache-tomcat-7.0.81.tar.gz apache

JMX下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.81/bin/extras/catalina-jmx-remote.jar bootstrap

catalina-jmx-remote.jar包下載完成後放到Tomcat的lib目錄下vim

[root@test01 lib]# pwd
/usr/local/tomcat/lib
[root@test01 lib]# wget
  • 在bin/catalina.sh添加以下內容(Windows環境catalina.bat文件)windows

[root@test01 lib]# cd /usr/local/tomcat/bin/
[root@test01 bin]# vim catalina.sh
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=7090
  -Dcom.sun.management.jmxremote.ssl=false    
  -Djava.rmi.server.hostname=192.168.100.1   
  -Dcom.sun.management.jmxremote.authenticate=true
  -Dcom.sun.management.jmxremote.password.file=/usr/local/softinstall/tomcat/conf/jmxremote.password 
  -Dcom.sun.management.jmxremote.access.file=/usr/local/softinstall/tomcat/conf/jmxremote.access"


  • 編輯訪問受權文件tomcat

[root@test01 lib]# cd /usr/local/tomcat/conf/
[root@test01 conf]# vim jmxremote.access
[root@test01 conf]# cat jmxremote.access
monitorRole readonly
controlRole readwrite
  • 編輯密碼文件服務器

[root@test01 conf]# vim jmxremote.password 
[root@test01 conf]# cat jmxremote.password
monitorRole tomcat
controlRole tomcat

注意:密碼文件應該是隻讀的,只能由Tomcat運行用戶。curl

更改密碼文件權限,不然彙報以下錯誤:

Error: Password file read access must be restricted: /usr/local/tomcat/conf/jmxremote.password

[root@test01 conf]# chmod 0400 jmxremote.password
[root@test01 conf]# ll jmxremote.password 
-r-------- 1 root root 36 Aug 25 15:47 jmxremote.password
  • 啓動Tomcat

[root@test01 conf]# ../bin/startup.sh 
Using CATALINA_BASE:   /usr/local/softinstall/tomcat
Using CATALINA_HOME:   /usr/local/softinstall/tomcat
Using CATALINA_TMPDIR: /usr/local/softinstall/tomcat/temp
Using JRE_HOME:        /usr/local/softinstall/jdk1.7.0_79
Using CLASSPATH:       /usr/local/softinstall/tomcat/bin/bootstrap.jar:/usr/local/softinstall/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@test01 conf]# netstat -nlput | grep java
tcp        0      0 :::7090                     :::*                        LISTEN      7329/java                     
tcp        0      0 ::ffff:127.0.0.1:7005       :::*                        LISTEN      7329/java                    
tcp        0      0 :::7080                     :::*                        LISTEN      7329/java

[root@test01 conf]# curl -I localhost:7080
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Fri, 25 Aug 2017 08:58:54 GMT

Tomcat啓動成功、JMX7090端口啓動成功

  • 在一臺windows服務器上部署Java環境

在Jdk的安裝目錄bin目錄下找到jvisualvm.exe (另外一個工具爲jconsole.exe也在bin目錄下,這裏使用jvisualvm工具)

C:\Program Files\Java\jdk1.8.0_131\bin

wKioL1mf6Z2ytYrJAADC2ohbj4s480.jpg-wh_50

雙擊運行jvisualvm.exe

wKiom1mf6jKDPtdAAAAbGcLCins603.jpg-wh_50

wKioL1mf6nDjKr-WAACnbAiX7lY771.jpg-wh_50

點擊——遠程——添加遠程主機——在彈出的窗口中填寫要遠程主機的名——點擊肯定

wKiom1mf6v-Qqv09AACgpNLyihM519.jpg-wh_50


wKioL1mf63GigLO6AAAiwF6i5Dk147.jpg-wh_50


應用程序——遠程——選擇之間添加的主機——右擊——添加jmx鏈接——在彈出的窗口中填寫鏈接信息——肯定


wKioL1mf7KLB99viAADIPT6-AkI267.jpg-wh_50

wKiom1mf7czTo1dTAADn3he54T4836.jpg-wh_50

鏈接成功

wKioL1mf7s7zlupPAAEFW0ySp_g323.jpg-wh_50

相關文章
相關標籤/搜索