Hi,

I was following this blog about running multiple nodes on the same host:

http://www.onemanclapping.org/2010/03/running-multiple-cassandra-nodes-on.html

The main nuisance here was that there is no easy way to specify the host IP address for JMX to bind to, it would always bind to all interfaces. The 'java.rmi.server.hostname' property did not work and I didn't want to pick different ports for all the different instances on the same host.

Also, I didn't want to create my own RMIServerSocketFactory with all the complexities associated with it, I was after a simple patch to the existing code.

I've fixed this by patching the default JVM RMI socket factory that is responsible for creating this server socket. It now supports the new 'com.sun.management.jmxremote.host' property.

To get this to work, save the Java code below into a file named sun/rmi/transport/proxy/RMIDirectSocketFactory.java.

Compile and create jmx_patch.jar from it and place it into the cassandra lib/ folder.

You then need to add the following line to conf/cassandra-env.sh:

JVM_OPTS="$JVM_OPTS -Xbootclasspath/p:../lib/jmx_patch.jar -Dcom.sun.management.jmxremote.host=127.0.0.2"

This will then bind the JMX service only to address 127.0.0.2. The 2 other random RMI listening ports will still bind to all interfaces, but that is fine as they always pick a free port anyway.

You can now run multiple cassandra instances on a single host with all the default ports intact (e.g. 8080 for JMX for all of them).

Cheers,

        T.

===

package sun.rmi.transport.proxy;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.rmi.server.RMISocketFactory;

public class RMIDirectSocketFactory extends RMISocketFactory {

    public Socket createSocket(String host, int port) throws IOException
    {
        return new Socket(host, port);
    }

    public ServerSocket createServerSocket(int port) throws IOException
    {
        String jmx_host = 
System.getProperty("com.sun.management.jmxremote.host");
        String jmx_port = 
System.getProperty("com.sun.management.jmxremote.port");

        // Allow JMX to bind to specific address
if (jmx_host != null && jmx_port != null && port != 0 && Integer.toString(port).equals(jmx_port)) {
            InetAddress[] inetAddresses = InetAddress.getAllByName(jmx_host);
            if (inetAddresses.length > 0) {
                return new ServerSocket(port, 50, inetAddresses[0]);
            }
        }

        return new ServerSocket(port);
    }
}

Reply via email to