Monday, March 19, 2012

ServiceMix: Remote JMX Connection

I recently came across an issue where I was was unable to make a remote JMX connection to an instance of Apache ServiceMix which was running on a remote Linux server. In this post I will document the configuration needed to make a successful remote JMX connection to ServiceMix deployed on Cent OS Server 6.2 using JConsole or VisualVM.

When Apache ServiceMix is deployed to a Windows system you should be able to make a remote JMX connection using JConsole or VisualVM without an issue straight out-of-the-box. However, with Linux there may be additional configuration required before this remote JMX connection can be made. In order to make a remote JMX connection, the following property should be set on the JVM:

-Dcom.sun.management.jmxremote

A quick check of the [install_dir]/bin/servicemix script will confirm this property is being set on the Linux JVM, so why can't the connection be made?

If you are experiencing an issue making a remote JMX connection to an instance of Apache ServiceMix running on a Linux server check the following two items:

1) The result of hostname -i

hostname -i

If this command returns with the address 127.0.0.1 then the /etc/hosts file will need to be edited so that the hostname resolves to the host IP address. The IP address of the host can found by running the the following command:

I have noticed that if the result of "hostname -i" returns something similar to the following, the remote JMX connection should still work as long as a domain has been configured on the localhost entry in /etc/hosts:

If a domain has not been configured on the localhost entry then the remote JMX connection will fail. If for some reason you cannot or choose not to have a domain on the localhost entry, you can edit the JMX serviceURL property in the org.apache.karaf.management.cfg file, which is located in the [install_dir]/etc, as follows by changing "localhost" to the host IP address, "192.168.26.176" in my case:

These rules could have been configured more securely by adding a specific source for the connection, however for this example I will accept connections from any source on ports 1099 and 44444.

The last thing you will want to do is save these changes to the iptables so that they persist a system reboot by running the following command:

/sbin/service iptables save

Seeing it in action

Now that the configuration has been taken care of you should now be able to make a remote JMX connection to Apache ServiceMix using the following URL:

service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root

Where "localhost" would be replaced by the IP address or hostname of the remote machine.

Remember that the default configuration for ServiceMix 4.4.1 requires the username/password of smx/smx on the JMX connection.

Conclusion

At first it might seem baffling as to why you are unable to make a remote JMX connection to a Linux server but the resolution is really quite simple. This issue is listed on the Oracle page regarding the FAQ of JConsole and Remote Management. Have a look at the FAQ if you have any further questions, or to see how the connection can be filtered to a specific source address.