Not able to connect to Remote JMX from visualVM - java

I am trying to connect to JMX running on Linux machine from the visualVM running on windows machine. I am using following settings for visualVM.
java -server -Dcom.sun.management.jmxremote -Djava.security.policy=~/jmx.all.policy -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=<mymachinesIP> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8766 myApp
myApp starts correctly
security policy file is as follows :
grant {
permission java.security.AllPermission;
};
netstat -an | grep 9000 // doesn't return anything i.e. port is not open
I tried everything on these forums but still not able to find any solution. Any help will be appreciated. Jstatd works fine though.

Related

How to connect Spring Boot application remotely in Visual VM?

I am new to Visual VM, how to connect to Spring Boot application remotely in Visual VM?
Multiple instances are running as a java -jar app.jar with random ports. How to connect from Visual VM, I have root access to the remote system. Do I need to enable any security configuration?
In the local system, applications shows up automatically but when I entered remote system IP address it's prompting Add JMX connection and Add jstatd connection.
We need to specify the remote IP ADDRESS and expose the listening PORT while running the jar.
Syntax:
java
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=<PORT>
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=<IP_ADDRESS>
-Dcom.sun.management.jmxremote.rmi.port=<PORT>
-jar app-1.0.0-SNAPSHOT.jar
Example: Listening port is 6001 and available for remote ip address 192.168.0.23
java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=6001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.0.23 -Dcom.sun.management.jmxremote.rmi.port=6001 -jar app-1.0.0-SNAPSHOT.jar
For More details about set up Visual VM https://github.com/M-Thirumal/installation_guide/blob/master/visualVm/visualvm_remote_set_up.md
I encountered this dilemma with Spring Boot as well. But I was not using a jar. I passed the jmx arguments to maven to profile the application without having to build a jar first.
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"
For more details, I documented my steps here.

Distributed Java RMI in VM(s) [duplicate]

I've setup a VM on Fedora 17 with KVM and have configured a bridge network for the KVM. Both the host and the VM use manual IP configuration, with the host's IP as 192.168.0.2, the VM's 192.168.0.10.
From the VM I can connect to the host without any problems, but from the host I can't SSH to the VM,even though I still can ping the KVM from the host. Trying to ssh just gives me the result "no route to host".
Oh, I have iptables disabled so I don't think this is the problem of the firewall.
Also ensure that the kernel is configure for ip forwarding:
$ sudo sysctl -a | grep net.ipv4.ip_forward
net.ipv4.ip_forward = 1
It should have a value of 1, not 0. If needed, enable with these commands:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
There are two ways :
* Using proxy tunnel to create a channel for host from guest :
From guest run following command :
ssh -L 2000:localhost_ip:2000 username#hostip
explore ssh man to get the inside.
* Difficult to setup, but proper configuration while running guest :
follow
http://www.cse.iitd.ernet.in/~prathmesh/random.html#Connecting_qemu_guest_to_real_network

Using VisualVM on tomcat 8 running on EC2

I am trying to use VisualVM in my system to monitor a Tomcat instance running over EC2. I tried steps provided in multiple blogs about how to configure it, but still when I try to run tomcat it gives me following error.
./catalina.sh: 5: /home/gvr/apache-tomcat-8.0.18/bin/setenv.sh: -Dcom.sun.management.jmxremote: not found
I added following statement in server.xml
<listener classname="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
rmiregistryportplatform="10001"
rmiserverportplatform="10002"
uselocalports="true" />
And my setenv.sh is as follows
CATALINA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=ec2-xx-xxx-xx-xx.ap-southeast-1.compute.amazonaws.com"
$CATALINA_OPTS
Besides this I have added, catalina-jmx-remote.jar in tomcat's lib directory
Could anyone please provide me some hint, what is possibly going wrong. I tried everything I have found related to configuring VisualVM
I am running Tomcat 8.0.18, java 8 over ubuntu
I believe there are two issues
formatting in setenv.sh, you need \ to split across lines
last line $CATALINA_OPTS which tries to execute the arguments, hence -Dcom.sun.management.jmxremote not found...
Suggested fix
CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=ec2-xx-xxx-xx-xx.ap-southeast-1.compute.amazonaws.com"
echo $CATALINA_OPTS
I also tried using the JmxRemoteLifecycleListener and it didn't work for me.
Here it is how I did it:
1)I choose 1005 as jmx port and my setenve.sh is like:
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10005 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost"
2) redirect using ssh the jmx port and the rmi
3) Run visualvm using the following uri: service:jmx:rmi:///jndi/rmi://localhost:10005/jmxrmi
If you need more information have a look to this post:
http://ignaciosuay.com/how-to-connect-a-java-profiler-like-visualvm-or-jconsole-to-a-remote-tomcat-running-on-amazon-ec2/

How to enable the JMX of cluster servers on Weblogic?(not the Weblogic AdminServer itself)

I am running Weblogic 12c on CentOS6. I have enabled the JMX on Weblogic AdminServer.
But I want to enable the JMX on the cluster servers such as ms1 listed below to monitor specific Java service. What shall I do? Thank you!
Servers:AdminServer(admin)
Clusters: ms1/ms2/ms3
[root#weblogic61 bin]# ps -ef |grep java
weblogic 3618 3571 0 Jun04 ? 03:14:41 /home/jdk/jdk1.7.0_45/bin/java -server -Xms1024m -Xmx2048m -XX:MaxPermSize=1024m -Dweblogic.Name=ms1 -Djava.security.policy=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Dweblogic.security.SSL.trustedCAKeyStore=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/cacerts -Djava.endorsed.dirs=/home/jdk/jdk1.7.0_45/jre/lib/endorsed:/home/weblogic/Oracle/Middleware/wlserver_12.1/endorsed -da -Dplatform.home=/home/weblogic/Oracle/Middleware/wlserver_12.1 -Dwls.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.management.discover=false -Dweblogic.management.server=http://192.168.97.61:7001 -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/home/weblogic/Oracle/Middleware/patch_wls1211/profiles/default/sysext_manifest_classpath:/home/weblogic/Oracle/Middleware/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
root 27588 27541 41 09:56 pts/0 00:00:25 /home/jdk/jdk1.7.0_45/bin/java -server -Xms1024m -Xmx2048m -XX:MaxPermSize=1024m -Dweblogic.Name=AdminServer -Djava.security.policy=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Djava.endorsed.dirs=/home/jdk/jdk1.7.0_45/jre/lib/endorsed:/home/weblogic/Oracle/Middleware/wlserver_12.1/endorsed -Djava.rmi.server.hostname=192.168.97.61 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -da -Dplatform.home=/home/weblogic/Oracle/Middleware/wlserver_12.1 -Dwls.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.management.discover=true -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/home/weblogic/Oracle/Middleware/patch_wls1211/profiles/default/sysext_manifest_classpath:/home/weblogic/Oracle/Middleware/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
root 27638 27312 0 09:57 pts/1 00:00:00 grep java
zabbix 27853 1 0 Jun13 ? 00:14:16 java -server -classpath lib:lib/logback-classic-0.9.27.jar:lib/logback-core-0.9.27.jar:lib/org-json-2010-12-28.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-2.0.12.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java.pid -Dzabbix.listenIP=0.0.0.0 -Dzabbix.listenPort=10052 -Dzabbix.startPollers=5 com.zabbix.gateway.JavaGateway
The first question is where are those settings coming from for your admin server. My guess is you need to edit startWebLogic.sh and find where the following are being set:
JAVA_OPTIONS="-Dcom.sun.management.jmxremote.port=12345"
JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTIONS="${JAVA_OPTIONS} -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder"
export JAVA_OPTIONS
Thos settings are probably being explicitly set for your admin server only based on an if statement or some such.
You can also set those -D values for your managed server by going to:
Admin Console -> Servers -> MS -> Server Start -> JVM Arguments
Last, in the Weblogic Domain->Configuration->General->Advanced
Enable both - Platform MBean Server Enabled and Platform MBean Server Used
Admin Console -> Servers -> Server-1 -> Server Start -> JVM Arguments
-DUseSunHttpHandler=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.20.209
Admin Console -> Servers -> Server-2 -> Server Start -> JVM Arguments
-DUseSunHttpHandler=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8502 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.20.209
along with below command line parameters ,
-Dcom.sun.management.jmxremote.port='you jmx port'
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder
Sometimes in the linux servers , imx connection doesn't get succeeded. that is because , in cloud linux host, in /etc/hosts so that the hostname resolves to the host address.
the best way to fix it is, ping the particular linux server from other machine in network and use that host IP address in the
-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.
But never rely on the ipaddress that you get from linux server using ifconfig.me. the ip that you get there is masked one which is present in the host file.

Can't connect jconsole to remote server, tomcat failing to start

Trying to connect jconsole to a remote server.
I added this to my catalina.sh:
export JAVA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9005 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=xx.xx.xx.xx"
catalina.out shows:
Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: myhostname: myhostname
Not sure why it repeats my hostname in the error message?
BTW, since I set authentication to false, in the jconsole app, do I leave username/password blank or is that for logging into the server?
You have to add the same host name in /etc/hosts file as you have defined in /etc/sysconfig/network file.
This is how I solved my problem.
I have found the solution for this issue.
Add the following in your catalina.sh file:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=7010 -Djava.rmi.server.hostname=${IP}"
Also add the following line in your /etc/init.d/hosts file:
127.0.0.1 localhost <your_hostname>
This resolved the issue. I am able to run jconsole as well as jvisualvm on this port now.
I hope this helps !
If you want to get the IP address dynamically you can try:
IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=${IP}"
If you use '\' in your 'export' statement, remove those.
To connect to remote java process, Use IP address of the server where your java process (tomcat instance) is running. The UnknownHostException is thrown when IP address could not be determined, so another option is to add the name - IP address definition to your hosts file.
You can try adding the parameters that you have added in JAVA_OPTS to CATALINA_OPTS. It should work that way.
Also make sure u are making the settings with the same profile login from where you are running tomcat.

Categories