Thursday 15 March 2012

java - How connect to cassandra cluster via 192.168.x.x ip addres? -



java - How connect to cassandra cluster via 192.168.x.x ip addres? -

this question has reply here:

can't connect cassandra - nohostavailableexception 2 answers

here simple programme test connection cassandra:

package testjava.db.cassandra; import com.datastax.driver.core.cluster; import com.datastax.driver.core.session; public class connectiontester { public static void main (string[] args) { session session = null; seek { cluster cluster = cluster.builder().addcontactpoint("192.168.1.2").build(); session = cluster.connect("myspace"); system.out.println(session.getstate()); } grab (exception ex) { ex.printstacktrace(); } { if (session != null) { session.close(); } } } }

when tun get:

com.datastax.driver.core.exceptions.nohostavailableexception: host(s) tried query failed (tried: /192.168.1.2:9042 (com.datastax.driver.core.transportexception: [/192.168.1.2:9042] cannot connect)) @ com.datastax.driver.core.controlconnection.reconnectinternal(controlconnection.java:199) @ com.datastax.driver.core.controlconnection.connect(controlconnection.java:80) @ com.datastax.driver.core.cluster$manager.init(cluster.java:1199) @ com.datastax.driver.core.cluster.init(cluster.java:154) @ com.datastax.driver.core.cluster.connect(cluster.java:230) @ com.datastax.driver.core.cluster.connect(cluster.java:263) @ testjava.db.cassandra.connectiontester.main(connectiontester.java:11) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.intellij.rt.execution.application.appmain.main(appmain.java:134)

when alter localhost 192.168.1.2 every thing works. ipconfig windows command returns:

ethernet adapter local area connection: description . . . . . . . . . . . . . : realtek pcie gbe family controller physical address. . . . . . . . . . . : 40-61-86-7c-4b-0f dhcp enabled. . . . . . . . . . . . . : yes autoconfiguration enabled . . . . . . : yes ipv4-address. . . . . . . . . . . . . : 192.168.1.2(preffered) subnet mask . . . . . . . . . . . . . : 255.255.255.0 default gateway . . . . . . . . . . . : 192.168.1.1 dhcp-server . . . . . . . . . . . . . : 192.168.1.1 dns-servers . . . . . . . . . . . . . : 192.168.1.1

so clear ip address 192.168.1.2

important

yes can remain with localhost or 127.0.0.1 wana know why illustration above not work. when specify 192.168.1.2 address , run application on virtual machine not work too, when ping command works.

configure rpc_address in cassandra.yaml point address client utilize connect cassandra.

these 3 addresses configurable in cassandra.yaml.

listen address - ip address other cassandra nodes utilize talk node. if on cloud, internal ip address here performance.

rpc address - address client connects to, 1 want configure ip accessible client machine.

broadcast address - if using multiple info centers or aws regions, not nodes have access each other via internal ip. can specify external ip address nodes in different info centers can still talk each other. in many cases don't need setting @ all, default hear address.

java windows-7 cassandra ip datastax-java-driver

No comments:

Post a Comment