如何连接到本地cassandra db [英] How do I connect to local cassandra db
问题描述
我有一个本地运行的cassandra db。我可以看到它在Ops中心工作。但是,当我打开开发中心并尝试连接我得到一个隐藏的无法连接的错误。
如何获得我需要的确切的名称/ connectionstring
要连接到的主机名/ IP在 listen_address
属性。如果您只从您的本地主机(沙箱计算机)连接到Cassandra,那么您可以设置 listen_address
在您的cassandra.yaml中:
listen_address:localhost
/ pre>
当您启动Cassandra时,您应该在STDOUT或system.log中看到与此相似的行(为了简洁,删除时间戳):
开始在localhost / 127.0.0.1上监听CQL客户端:9042 ...
绑定节俭服务到localhost / 127.0.0.1:9160
聆听thrift客户端...
这些行表示您应该使用哪个地址连接到您的群集。第一种测试连接的方法是使用
clqsh
。注意,cqlsh默认会连接到localhost。如果您连接到除localhost之外的主机/ IP,则需要在命令行上指定。$ cqlsh
连接到本地主机上的测试集群:9042。
[cqlsh 5.0.1 |. Cassandra 2.1.0-rc5-SNAPSHOT | CQL spec 3.2.0 |本机协议v3]
使用HELP获取帮助。
cqlsh>
如果这个工作正常,那么你也应该能够从DataStax Dev Center通过定义到localhost的连接,如下所示:
此时,您应该能够通过应用程序代码连接(显示Java CQL3驱动程序):
cluster = Cluster.builder()。addContactPoint(localhost)。
元数据元数据= cluster.Metadata;
Console.WriteLine(Connected to cluster:+ metadata.ClusterName.ToString());
会话session = cluster.connect();
I have a cassandra db running locally. I can see it working in Ops Center. However, when I open dev center and try to connect I get a cryptic "unable to connect" error.
How can I get the exact name / connectionstring that I need to use to connect to this local cassandra db via dev center?
解决方案The hostname/IP to connect to is specified in the
listen_address
property of your cassandra.yaml.If you are connecting to Cassandra from your localhost only (a sandbox machine), then you can set thelisten_address
in your cassandra.yaml accordingly:listen_address: localhost
When you start Cassandra, you should see lines similar to this either in STDOUT or in your system.log (timestamps removed for brevity):
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...
These lines indicate which address you should be using to connect to your cluster. The first way to test your connection, is with
clqsh
. Note that cqlsh will connect to "localhost" by default. If you are connecting to a host/IP other than localhost, then you will need to specify it on the command line.$ 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>
If this works, then you should also be able to connect (and test) from DataStax Dev Center (also on your local machine) by defining a connection to localhost, like this:
At this point, you should be able to connect via your application code (Java CQL3 driver shown):
cluster = Cluster.builder().addContactPoint("localhost").build(); Metadata metadata = cluster.Metadata; Console.WriteLine("Connected to cluster: " + metadata.ClusterName.ToString()); Session session = cluster.connect();
这篇关于如何连接到本地cassandra db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!