2014-09-04 65 views
1

我有一个本地运行的cassandra db。我可以看到它在Ops Center中工作。但是,当我打开开发中心并尝试连接时,我得到一个神秘的“无法连接”错误。如何连接到本地cassandra db

如何获得我需要通过开发中心连接到本地cassandra db的确切名称/连接字符串?

+0

哪个版本卡桑德拉您使用的是? – 2014-09-05 02:11:25

+1

你的cassandra.yaml中的“listen_address”的值是什么? – Aaron 2014-09-05 03:51:09

+1

'cqlsh'在你的终端上工作吗? – phact 2014-09-07 16:32:33

回答

3

的主机名/ IP对在您cassandra.yaml.If要连接到卡桑德拉从本地主机只(沙箱机)的listen_address属性指定连接,然后就可以设置listen_address在cassandra.yaml因此:

listen_address: localhost 

当您启动卡桑德拉,你应该看到无论是在标准输出或在您的SYSTEM.LOG与此类似线(为简洁,删除时间戳):

Starting listening for CQL clients on localhost/127.0.0.1:9042... 
Binding thrift service to localhost/127.0.0.1:9160 
Listening for thrift clients... 

这些线指示哪些加你应该使用连接到你的集群。测试连接的第一种方法是使用clqsh。请注意,默认情况下,cqlsh将连接到“localhost”。如果要连接到除localhost之外的主机/ IP,则需要在命令行上指定它。

$ cqlsh 
Connected to Test Cluster at localhost:9042. 
[cqlsh 5.0.1 | Cassandra 2.1.0-rc5-SNAPSHOT | CQL spec 3.2.0 | Native protocol v3] 
Use HELP for help. 
cqlsh> 

如果一切正常,那么你也应该能够连接(和测试)由DataStax开发中心(也是你的本地计算机上)通过定义为localhost的连接,就像这样:

enter image description here

在这一点上,你应该能够通过你的应用程序代码连接(如图所示的Java CQL3司机):

cluster = Cluster.builder().addContactPoint("localhost").build(); 
Metadata metadata = cluster.Metadata; 
Console.WriteLine("Connected to cluster: " + metadata.ClusterName.ToString()); 
Session session = cluster.connect();