问题
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:
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;};
I started the
Jstatd
asjstatd -J-Djava.security.policy=jstatd.all.policy
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
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*
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:
- File -> Add JMX Connection
- Type: yourHostName:9000 and click OK
- 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:
- 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) - 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
) - Open those 4 ports on your remote host and make them available to your local machine:
1099
,1100
,1101
and1102
- Launch JVisualVM
- 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") - 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" - Your Java process will appear twice: one from the "jstatd" connection type, and one from the "JMX" connection type.
- Right-click on "Remote" > "Add Remote Host..." and enter your remote host name in "Host name" (if you don't use the port
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