Not able to Connect a Remote Host to the VisualVM

萝らか妹 提交于 2020-01-11 15:38:12

问题


I am new to Java and I'm facing a problem in connecting a Remote Host to the JVisualVM.

I've searched the Internet and followed all the steps mentioned there but still am not able to resolve the issue. The steps I followed are:

  1. I started the jstatd on the remote server by first creating a jstatd.all.policy file in the $JAVA_HOME/bin. The file contained: grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission;};

  2. I started the Jstatd as jstatd -J-Djava.security.policy=jstatd.all.policy

  3. I started the Java application on the remote host as :

    java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false application_name
    
  4. I then started as instance of the JVisualVM on my local machine and as I added the remote host, it got connected but i wasn't able to see any of the Java processes.

Can anyone please help me with this.

Thanks.


回答1:


I encountered similar problems when connecting to Glassfish application server. See solutions that worked for me as they can be same for You:

  • Try setting on your application:

    -Djava.rmi.server.hostname=*Remote_Server_External_IP_Address*

The mentioned IP address should be server external IP (may sound silly but it worked for me). The main problem in my case was JMX pointing to the localhost and looping. In config files the exact IP address should be set to the remote host. I described it as 'Problem 2' In my blog: handling connection problems
  • If Firewall block is an issue then I recommend trying XMing with SSH tunnel (which is simple to set). Here is instruction, if You encounter problems setting it:
    Remote use of VisualVM with Xming (my blog) Biggest advantage of using XMing is that it will work almost always when SSH is enabled. You just have to place VisualVM files on the remote host and run it from command line. XWindow will show VisualVM Window on Your local computer.

  • There is a chance that it is VisualVM issue - try using some other tool just to verify what is wrong. I recommend JConsole. It works similar to VisualVM and I also described details on my blog




回答2:


You need to start jstatd with the additional option that points to the server's external IP or hostname:

statd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=my_server_ip/hostname

Answer based on: https://java.net/projects/visualvm/lists/users/archive/2010-03/message/8




回答3:


To connect to a remote VM you have to start that remote VM with specific options:

java
 -Dcom.sun.management.jmxremote
 -Dcom.sun.management.jmxremote.port=9000
 -Dcom.sun.management.jmxremote.ssl=false
 -Dcom.sun.management.jmxremote.authenticate=false
class

After the VM is started, go to your VisualVM and do the following:

  1. File -> Add JMX Connection
  2. Type: yourHostName:9000 and click OK
  3. On the left you will have the added JMX connection, double click on it and that's it!

More details on the Java Monitoring and Management Platform can be found here.




回答4:


Start jstatd in nohup on the server which needs to be monitored and connect VisualVM to the jstatd port, following below steps:

Step 1 : Create start-jstatd.sh and copy the below content:

nohup jstatd -p 1099 -J-Djava.security.policy=<(echo 'grant codebase "file:${java.home}/../lib/tools.jar" {permission java.security.AllPermission;};') &

Step 2: Give executable permission to the file:

$ chmod a+rwx start-jstatd.sh

Step 3: Start jstatd:

$ sh start-jstatd.sh

Step 4: Add Remote Host in VisualVM:

Step 5: Add JMX Connection to the Remote Host, as shown in the below image and Click OK button:




回答5:


Here are the steps to do this:

  1. Launch an ejstatd in your remote host this way (in ejstatd folder): mvn exec:java -Djava.rmi.server.hostname=<remote_host_name> -Dexec.args="-pr 1099 -ph 1100 -pv 1101" (used for "jstatd" type connection) (only specify -Djava.rmi.server.hostname if the hostname of your remote host does not match with the one you are seeing from your local network)
  2. Launch your Java application with those additional Java parameters: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1102 -Dcom.sun.management.jmxremote.rmi.port=1102 -Djava.rmi.server.hostname=<remote_host_name> (used for "JMX" type connection) (same remark as the previous point for -Djava.rmi.server.hostname)
  3. Open those 4 ports on your remote host and make them available to your local machine: 1099, 1100, 1101 and 1102
  4. Launch JVisualVM
    1. Right-click on "Remote" > "Add Remote Host..." and enter your remote host name in "Host name" (if you don't use the port 1099, you can change this in the "Advanced Settings")
    2. Right-click on the remote host you've just created > "Add JMX Connection..." and enter "<remote_host_name>:1102" in "Connection" input, and check "Do not require SSL connection"
    3. Your Java process will appear twice: one from the "jstatd" connection type, and one from the "JMX" connection type.

Disclaimer: I'm the author of the open source ejstatd tool.



来源:https://stackoverflow.com/questions/7871723/not-able-to-connect-a-remote-host-to-the-visualvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!