Using VISUALVM to remotely monitor JVM Linux Server configuration methods

Source: Internet
Author: User
Tags cpu usage visualvm

The VisualVM is an all-in-one performance monitoring and failure analysis tool from the JDK, including CPU usage, JVM heap memory consumption, real-time monitoring of threads, class loading, memory dump file analysis, and visual analysis of garbage collection operations, which is helpful for troubleshooting and performance tuning. After installing the JDK in Windows, VISUALVM is located under%java_home%/bin/and executes the Jvisualvm.exe directly, a main operating interface

VISUALVM will automatically detect the JVM in the native running and establish a connection, this article mainly introduces the configuration method of connecting the remote Linux server, the test environment is CentOS 6.5,JDK8,TOMCAT8.

VISUALVM There are two ways to connect to a remote server: JMX and jstatd, neither of which can perfectly support all features, such as JMX does not support VISUALGC,JSTATD does not support CPU monitoring, the actual use can be configured simultaneously and on-demand.

1 Pre-configuration preparation

We need to check the linux hostname matching IP first, execute

Hostname-i

If the matching result is unrecognized or 127.0.0.1, you will need to manually configure the hostname and IP mapping. Suppose the IP to be used to establish the connection is 192.168.11.233, and the hostname is mylinux:

Vi/etc/hosts

Add a row

192.168.11.233 Mylinux

2 Configuring JMX2.1 Create setenv.sh

Enter the Tomcat/bin directory

VI setenv.sh

    1. #!/bin/shexport java_opts="$JAVA _opts-xms512m-xmx512m-dcom.sun.management.jmxremote.ssl=false- Dcom.sun.management.jmxremote.password.file=. /conf/jmxremote.password-dcom.sun.management.jmxremote.access.file=. /conf/jmxremote.access "

(-xms512m-xmx512m is not a required parameter, it is just a hint that can be adjusted together with the JVM parameters)

Set permissions

chmod +x setenv.sh

2.2 Adding listener to Server.xml

Enter the tomcat/conf directory

VI Server.xml

    1. <listener classname="Org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiregistryportplatform=" 10001 "rmiserverportplatform="10002 "/>

The port can be modified according to the actual situation, after the added structure such as

2.3 Jmx Access Control files

Enter the tomcat/conf directory and execute

CP $JAVA _home/jre/lib/management/jmxremote.password.template JMXREMOTE.PASSWORDCP $JAVA _home/jre/lib/management/ Jmxremote.access jmxremote.access

And then

VI Jmxremote.password

Uncomment the following two lines
#monitorRole QED
#controlRole

You can also customize your account by adding a line in the format username password, so you need to modify the Jmxremote.access

VI jxmremote.access
At the bottom of the add
Username ReadWrite

Modify Permissions

chmod Jmxremote.password
chmod jxmremote.access

2.4 Adding Catalina-jmx-remote.jar

Http://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina-jmx-remote

Copy to tomcat/lib directory after download

At this point, the configuration work is complete, but you also need to add two ports in 2.2 to the firewall allow rule

2.5 Setting up a firewall

Vi/etc/sysconfig/iptables

Join before a input-j REJECT--reject-with icmp-host-prohibited

    1. -A input-p tcp-m state--state new-m TCP--dport 10001-j ACCEPT
    2. -A input-p tcp-m state--state new-m TCP--dport 10002-j ACCEPT

Service Iptables Restart

Telnet the server's 10001 and 10002 ports on the client, if it is correct.

2.6 Testing

Start Jvisualvm.exe on the client, add remote host on the left side of the tree menu remotely, and host name fill in server IP

After determining, a new child node appears under the remote, and the JMX connection is added right-click on the child node

Connect the input ip:10001, and note that this port is the Rmiregistryport configured in 2.2 steps. Check the use of security credentials, user name and password is 2.3 steps in the Jmxremote.password file in the user name and corresponding password. Tick Save security credentials

SSL is not enabled in the configuration of this article, and when you click OK, you are prompted to confirm that you are not trying to connect using SSL, and select Yes. If everything goes well. A JMX connection subnode appears under the server node, and the feature interface opens after double-clicking.

Try a powerful visual GC plugin, unfortunately, "not supported by this JVM", if you want to use this plug-in, you need to configure the JSTATD connection method, the following jstatd configuration.

3 Configuring the jstatd3.1 configuration Security Policy VI $JAVA _home/jre/lib/security/java.policy
At the bottom of the file}; Before adding
Permission java.security.allpermission;3.2 start JSTATDCD $JAVA _home/bin
./jstatd-j-djava.security.policy=all.policy & starts after the registration port 1099 and a random connection port, the registration port can also be specified by the-p parameter, such as./JSTATD- J-djava.security.policy=all.policy-p 10003 &3.3 Setting up a firewall in addition to adding 1099 to the firewall rules, you need to find another random port and join the rule to execute the NETSTAT-ANP | grep *jstatd can be seen in addition to 1099,JSTATD also listen to the 53040 port, add this also to the rule, adding method reference 2.5 (Note: This random port will change after the restart) 3.4 Test start VISUALVM, Because the server node has been added when configuring JMX, if it is configured correctly, VISUALVM will usually automatically detect the JSTATD connection and add the node if it is not automatically added, you can check whether the port can connect and try to add the connection VISUALGC interface (end) manually

This article permanently updates the link address : http://www.linuxidc.com/Linux/2017-01/139409.htm

Remote monitoring of JVM Linux server configuration using VISUALVM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.